First time here? Check our help page!
2

How to getAirloopHVACByName

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?
TomB's avatar
1.7k
TomB
asked 2017-04-10 15:59:02 -0500
__AmirRoth__'s avatar
4.4k
__AmirRoth__
updated 2017-08-05 07:34:29 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

3

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
Julien Marrec's avatar
29.7k
Julien Marrec
answered 2017-04-10 16:06:42 -0500, updated 2017-04-10 16:12:38 -0500
edit flag offensive 0 remove flag delete link

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's avatar Julien Marrec (2017-04-10 16:16:08 -0500) edit

python has spoiled me

TomB's avatar 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's avatar Julien Marrec (2017-04-11 05:51:45 -0500) edit
add a comment see more comments