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

How to make a choice argument for ALL objects of a certain type (measure)?

asked 2015-04-16 11:53:34 -0600

updated 2017-05-05 09:25:00 -0600

Here is what I have so far:

Here I make a choice argument with all the refrigeration cases in the model ref_case = OpenStudio::Ruleset::makeChoiceArgumentOfWorkspaceObjects("ref_case","OS_Refrigeration_Case".to_IddObjectType,model,true) ref_case.setDisplayName("Apply the measure to") args << ref_case

I would like to also have the option of "All refrigeration cases". I have seen many examples that use the following method:

Here I add building to string vector with space type building = model.getBuilding space_type_handles << building.handle.to_s space_type_display_names << "Entire Building"

However, I would like to maintain the 'makeChoiceArgumentOfWorkspaceObjects("ref_case","OS_Refrigeration_Case".to_IddObjectType,model,true)'

In staying with this approach, how would I add an option for "All Refrigeration Cases"?

edit retag flag offensive close merge delete


In addition to making a choice argument for "all cases", is it difficult to have the option to select more than one case? For example, if I wanted to manually select all low temperature cases.'s avatar  ( 2015-04-16 11:58:02 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-17 12:09:31 -0600

I often end up not using the makeChoiceArgumentOfWorkspaceObject, and instead use a custom version of makeChoiceArgument that gives me more control of sort and filtering. Below is an example for light definitions. Note that the handle is what is passed to the run section, vs. the display name

#populate choice argument for lights_defs that are applied to surfaces in the model
lights_def_handles =
lights_def_display_names =

#putting space types and names into hash
lights_def_args = model.getLightsDefinitions
lights_def_args_hash = {}
lights_def_args.each do |lights_def_arg|
  lights_def_args_hash[] = lights_def_arg

#looping through sorted hash of lights_defs do |key,value|
  #only include if it is used in a space, and has a non 0 value
  if value.quantity > 0 and not value.wattsperSpaceFloorArea.empty?
    lights_def_handles << value.handle.to_s
    lights_def_display_names << key

#make an argument for lights_def
lights_def = OpenStudio::Ruleset::OSArgument::makeChoiceArgument("lights_def", lights_def_handles, lights_def_display_names,true)
lights_def.setDisplayName("Choose a Watt per Area Lights Definition to Add Costs to.")
args << lights_def

Below is what would be in the run section

#assign the user inputs to variables
lights_def = runner.getOptionalWorkspaceObjectChoiceValue("lights_def",user_arguments,model) #model is passed in because of argument type

#check the Definition for reasonableness
if lights_def.empty?
  handle = runner.getStringArgumentValue("lights_def",user_arguments)
  if handle.empty?
    runner.registerError("No Lights Definition was chosen.")
    runner.registerError("The selected Lights Definition with handle '#{handle}' was not found in the model. It may have been removed by another measure.")
  return false
  if not lights_def.get.to_LightsDefinition.empty?
    lights_def = lights_def.get.to_LightsDefinition.get
    runner.registerError("Script Error - argument not showing up as Lights Definition.")
    return false
end  #end of if lights_def.empty?

@macumber may have examples on how to use the makeChoiceArgumentOfWorkspaceObjects. I think it handles sorting now by object name, if you don't want to filter it.

To address you question of selecting multiple objects, there are a few possible solutions, none of the very pretty.

  1. You can make a string argument where you have to know and enter the object names comma seperated. Then in the run section you can parse the string and find the objects.
  2. We have played around with the idea of a measure that would for example create bool arguments for each thermal zone, in the model, then you could check as many as you want to apply the measure two. This would actually look pretty nice, but wouldn't be as manageable in very large models. If you want to do a large parametric analysis having an unknown amount of user arguments could become problematic. If that isn't in your use case, you could do this direction.
  3. Sometimes I add the building object into the choice list. If that is chosen I use it as an "Apply to all" option. But that still is a 1 or all solution. You can't pick 3 items out.
  4. The last one is more of a future option. If you have used the SketchUp plugin, you are aware user scripts such ...
edit flag offensive delete link more


Odd, somehow my answer disappeared when I tried to update it. Fortunately I was able to go back on browser to recover text from the answer. Anyway the comment that was lost was asking for an example for Option 1. I added that at the end of the answer. You will have to click "more" to see it.

David Goldwasser's avatar David Goldwasser  ( 2015-04-17 12:10:57 -0600 )edit

Your Answer

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

Add Answer


Question Tools



Asked: 2015-04-16 11:53:34 -0600

Seen: 245 times

Last updated: Apr 17 '15