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

How to getAirloopHVACByName

asked 2017-04-10 15:59:02 -0500

TomB gravatar image

updated 2017-08-05 07:34:29 -0500

I'm trying to add zones to airloops, via a measure. Using the ruby console in Sketchup, I see a likely helper method

model.methods.grep(/getA/i)
... :getAirLoopHVACByName
myairloop = model.getAirLoopHVACByName("my air loop")

I have a few questions

  1. I can't find any documentation of that method on the aws sdk, is there a reason for that?
  2. Using getAirLoopHVACByName("my air loop") returns an OptionalAirLoopHVAC, does that mean it has not found 'my air loop' but returned something else?
  3. myairloop.name doesn't allow me to handle it by name. Is there another way to handle it by its name, e.g by looping over all air loops and then matching by name?
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2017-04-10 16:06:42 -0500

updated 2017-04-10 16:12:38 -0500

Here's how to use any of the getXXXXByName methods, which all return an OptionalXXXX object that you can call empty? (or is_initialized) on, and once you made sure it did find it, you can .get it:

air_loop_name = "my air loop"
# This returns an optional air loop
air_loop = model.getAirLoopByName(air_loop_name)

# If you couldn't find it
if air_loop.empty?
  puts "Couldn't match an AirLoopHVAC with the name #{air_loop_name}"
# Otherwise, get it (OptionalAirLoopHVAC > AirLoopHVAC)
else
  air_loop = air_loop.get
 // Do Stuff, eg:
 puts air_loop.name.to_s
end

Similarly, air_loop.name returns an OptionalString, meaning you need to call either .get or .to_s on it in order to get a String object.

For example, to list all the AirLoopHVAC names in your model:

model.getAirLoopHVACs.each do |loop|
  puts loop.name.to_s
end
edit flag offensive delete link more

Comments

Obviously if you're sure about the name of your AirLoopHVAC, you can go ahead and do air_loop = model.getAirLoopHVACByName("my air loop").get

Julien Marrec gravatar image Julien Marrec  ( 2017-04-10 16:16:08 -0500 )edit

python has spoiled me

TomB gravatar image TomB  ( 2017-04-11 05:26:32 -0500 )edit

To be fair, this has nothing to do with ruby as opposed to Python. If you were using the OpenStudio Python bindings, you'd still have to do the same (except you'd write model.getAirLoopHVACByName("my air loop").get()). This concept of Optional types comes from the underlying C++ boost library (see boost.optional or motivation). This avoids having to wrap calls to this in a try...except statement for example.

Julien Marrec gravatar image Julien Marrec  ( 2017-04-11 05:51:45 -0500 )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

1 follower

Stats

Asked: 2017-04-10 15:59:02 -0500

Seen: 46 times

Last updated: Apr 10 '17