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

Revision history [back]

There's zero reason it would come up empty if the model indeed has a loop by that name. Note that the name is case-sensitive.

I suggest debug printing all AirLoopHVAC's name.

puts "AirLoopHVAC names = #{model.getAirLoopHVACs.map(&:nameString)}"

If you wanted to grab something case-insentitively you could do something like

candidates = model.getAirLoopHVACs.select{|a| a.nameString.downcase == inputted_airloop_name.downcase }
raise "Not found" if candidates.empty?
# Name unicity is enforced in model SDK, so it's pointless to check if size > 1
a = candidates[0]

There's zero reason it would come up empty if the model indeed has a loop by that name. Note that the name is case-sensitive.

I suggest debug printing all AirLoopHVAC's name.

puts "AirLoopHVAC names = #{model.getAirLoopHVACs.map(&:nameString)}"

If you wanted to grab something case-insentitively you could do something like

candidates = model.getAirLoopHVACs.select{|a| a.nameString.downcase == inputted_airloop_name.downcase }
raise "Not found" if candidates.empty?
# Name unicity is enforced in model SDK, so it's pointless to check if size > 1
a = candidates[0]

A piece of advice: I strongly suggest you install ruby 2.7.2 (or 2.7.x at least), configure it to point to the openstudio SDK (see Getting Started - Install Ruby), and gem install pry. You'll have a REPL where you can easily debug that stuff.

And when writing measures, you can also run your tests from your system ruby, and where stuff goes sideways in your measure.rb you can (after gem install pry-byebug) insert

require 'pry-byebug'
byebug

When you run the test, this is going to throw you inside a REPL at that point, so you can inspect whatever is going on, without having to recreate the conditions. That's a major time saver if your code becomes complex