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

Can you return an OpenStudio runner print from a resource file?

asked 2015-10-30 06:40:01 -0500

updated 2015-10-30 06:41:21 -0500

I'm writing a measure that has a resource file that adds some methods to the OpenStudio::Model class.

Let's assume this is the entire content of resources/MyHelper.rb:

 class OpenStudio::Model::Model
    def helloworld()
      puts "Hello World!"
    end
end

In the measure.rb:

require_relative 'resources/MyHelper'
model.helloworld

How can I modify the MyHelper.rb so that instead of doing a puts statement it basically does a runner.registerInfo("Hello World!")?

Am I forced to pass the runner as an argument to each function of MyHelper.rb that needs to use it?

Also, I've seen the OpenStudio::logFree method, but I'm not sure what its purpose is and how to use it.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2015-10-30 09:34:53 -0500

The OpenStudio logging system is more for logging from within the C++, it isn't for logging in measures, that is what the runner is for. I suppose you could extend Model to have an instance variable @runner so you could set the runner on the model and then use it in all your functions. I'd prefer to just pass the runner in to each function though.

edit flag offensive delete link more

Comments

Passing the runner in as an argument is what I have used and it works well. The one thing to be careful of is using runner.registerAsNotApplicable or runner.registerError in a a helper method. The "return true" or "return false" doesn't stop the top level measure.rb from running. If I use that method after it runs I add a few lines of code in measure.rb to check if it was an error or NA as shown below (check below is just for error, not NA)

# get sql, model, and web assets
setup = OsLib_Reporting.setup(runner)
unless setup
  return false
end
David Goldwasser's avatar David Goldwasser  ( 2015-10-30 11:13:55 -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

1 follower

Stats

Asked: 2015-10-30 06:40:01 -0500

Seen: 76 times

Last updated: Oct 30 '15