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

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

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

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

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

Comments

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.

jstein@energystudioinc.com's avatar jstein@energystudioinc.com  ( 2015-04-16 11:58:02 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

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

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 = OpenStudio::StringVector.new
lights_def_display_names = OpenStudio::StringVector.new

#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.name.to_s] = lights_def_arg
end

#looping through sorted hash of lights_defs
lights_def_args_hash.sort.map 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
  end
end

#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.")
  else
    runner.registerError("The selected Lights Definition with handle '#{handle}' was not found in the model. It may have been removed by another measure.")
  end
  return false
else
  if not lights_def.get.to_LightsDefinition.empty?
    lights_def = lights_def.get.to_LightsDefinition.get
  else
    runner.registerError("Script Error - argument not showing up as Lights Definition.")
    return false
  end
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 ...
(more)
edit flag offensive delete link more

Comments

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 -0500 )edit

Your Answer

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

Add Answer

Careers

Question Tools

2 followers

Stats

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

Seen: 249 times

Last updated: Apr 17 '15