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

Open Studio: Air loop not recognized in model from Ruby measure script

asked 2023-06-01 18:19:05 -0500

MDW's avatar

Hi there, I am working on coding an ASHP measure for Open Studio in Ruby and am running into an issue where the name of an air loop specified in an user-input CSV is not recognized in the model (thus, retrieving it produces an "empty" result). I am getting the error message that I specified below when running the measure.

model_airloop = model.getAirLoopHVACByName(inputted_airloop_name)
if model_airloop.empty?
      runner.registerError("HVAC air loop template '#{inputted_airloop_name}' not found.")
      return false

The OS model does have an air loop that is named "inputted_airloop_name", but I am unexpectedly getting this error message, meaning the variable is coming up empty. Any ideas on potential causes of this error?

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-06-02 02:01:18 -0500

updated 2023-06-02 02:06:36 -0500

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 = #{}"

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

candidates ={|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'

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

edit flag offensive delete link more



Right. And just to be sure @MDW, if you have a loop named "inputted_airloop_name", then it's either:

inputted_airloop_name = "inputted_airloop_name"
model_airloop = model.getAirLoopHVACByName(inputted_airloop_name)


model_airloop = model.getAirLoopHVACByName("inputted_airloop_name")

EDIT: In your case (a string parsed from a CSV file), then it would definitely be:

model_airloop = model.getAirLoopHVACByName(inputted_airloop_name)
Denis Bourgeois's avatar Denis Bourgeois  ( 2023-06-02 05:19:00 -0500 )edit

Thanks for the comments. Unfortunately, putting the inputted_airloop_name in quotes did not resolve the issue, and printing out all AirLoopHVAC names outputs the names of all air loops I would have expected. Despite this, still seems to be coming up empty. Printed out the air loop object (<openstudio::model::optionalairloophvac:0x000001f23124dbf8>) - so it is an optional object that does not actually exist?

Looking into the debugging method you've mentioned Julien - thanks

MDW's avatar MDW  ( 2023-06-05 16:00:34 -0500 )edit

@MDW, I edited my initial comment. As you're parsing a CSV file, you definitely wouldn't want to put the object inputted_airloop_name in quotation marks. You may however be dragging whitespaces. Maybe try strip:

airloop_name = airloop_name.strip unless airloop_name.strip.nil?
model_airloop = model.getAirLoopHVACByName(airloop_name)

You could also compare (for debugging purposes):

p airloop_name
p airloop_name.strip
puts airloop_name
Denis Bourgeois's avatar Denis Bourgeois  ( 2023-06-05 17:17:43 -0500 )edit

Thanks, Denis. Printing the airloop name out before and after applying "strip" unfortunately still outputs the same airloop name (the one I am expecting to be non-empty), so not sure what the issue could be at this point.

MDW's avatar MDW  ( 2023-06-06 09:32:29 -0500 )edit

Hmm. airloop_name.strip should return nil (not the string) if there were no whitespaces. In any case, I think the next step for you would be to share the OSM file holding the targeted plant loop. And ideally an excerpt of the CSV file to parse (not the whole thing, just the few lines near/including the loop name).

Denis Bourgeois's avatar Denis Bourgeois  ( 2023-06-06 13:46:43 -0500 )edit

Your Answer

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

Add Answer

Training Workshops


Question Tools

1 follower


Asked: 2023-06-01 18:19:05 -0500

Seen: 41 times

Last updated: Jun 02 '23