Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
1

Delete existing OS:FuelFactors

asked Jan 29

updated Jan 29

I am writing a script to create new OpenStudio::Model::FuelFactors

Everything works fine but it does not delete the existing FuelFactor for that fuel.

How can I delete all the existing FuelFactors? I have tried some thing like:

model.getFuelFactors

but this method requires a Handle argument that I dont know.

Any ideas?

Thanks in advance.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered Jan 30

updated Feb 3

TL;DR: Getters follow the convention of being called get<ClassName>s().

The class is called FuelFactors. Note the existing s.

So logically, the getter is getFuelFactorss() (double s).

The same goes for getLightss().


If you want an explanation you didn't ask for, this is because we're using a C++ template: https://github.com/NREL/OpenStudio/bl...

template <typename T>
std::vector<T> getModelObjects(bool sorted = false);

This exposed to the target language via SWIG bindings, and we transform that to a method called get<T>s() automatically.

The same is true for the ruby IdfObject.to_ClassName(). The C++ equivalent is template<typename T> boost::optional<T> IdfObject::cast()


Here are all of the similar std::vector<T> get<T>s() that end with at least a double s, from python

import openstudio
import re
import inspect


RE_GET = re.compile(r'^get.+ss$')
getters = []
model = openstudio.model.Model()

for method_name in dir(model):
    method = getattr(model, method_name)
    if not inspect.ismethod(method):
        continue
    if not RE_GET.match(method_name):
        continue

    # Keep only those that take zero params
    if len(inspect.signature(method).parameters) != 0:
        continue
    getters.append(method_name)



['getAdditionalPropertiess',
 'getAirLoopHVACUnitaryHeatCoolVAVChangeoverBypasss',
 'getAirflowNetworkDuctViewFactorss',
 'getAirflowNetworkReferenceCrackConditionss',
 'getCoilHeatingGass',
 'getCoolingTowerPerformanceCoolToolss',
 'getDefaultSubSurfaceConstructionss',
 'getDefaultSurfaceConstructionss',
 'getElectricLoadCenterInverterPVWattss',
 'getExteriorLightss',
 'getFuelFactorss',
 'getGass',
 'getGeneratorPVWattss',
 'getHumidifierSteamGass',
 'getInternalMasss',
 'getLightss',
 'getMaterialPropertyMoisturePenetrationDepthSettingss',
 'getMaterialPropertyPhaseChangeHysteresiss',
 'getOutputEnvironmentalImpactFactorss',
 'getRefrigerationDefrostCycleParameterss',
 'getRunPeriodControlSpecialDayss',
 'getScheduleTypeLimitss',
 'getSurfacePropertyConvectionCoefficientss',
 'getSurfacePropertyGroundSurfacess',
 'getSurfacePropertyOtherSideCoefficientss',
 'getSurfacePropertySurroundingSurfacess',
 'getWaterUseConnectionss',
 'getWeatherFileDayss'
Preview: (hide)
link

Comments

1

Thank you for your reply. Once again you are a lifesaver. I also appreciate the extra explanation. I'm not familiariced with C++, but I was a bit confused because I searched the github repository for a getFuelFactors method but didn't find anything helpful.

mapascual's avatar mapascual  ( Jan 30 )

Yeah, the template makes it a bit harder to search in the github code, as well as the sdk documentation: https://s3.amazonaws.com/openstudio-s...

One thing that can help is in irb is to search for method names:

 m.methods.grep(/getFuel.*s$/).sort
  => [:getFuelFactors, :getFuelFactorss]
Julien Marrec's avatar Julien Marrec  ( Feb 3 )

A rough python equivalent: model = openstudio.model.Model(); [m for m in dir(model) if callable(getattr(model, m)) and 'FuelFactor' in m]

Julien Marrec's avatar Julien Marrec  ( Feb 3 )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: Jan 29

Seen: 80 times

Last updated: Feb 03