First time here? Check our help page!
3

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

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.

Julien Marrec's avatar
29.7k
Julien Marrec
asked 2015-10-30 06:40:01 -0500, updated 2015-10-30 06:41:21 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

3

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.

macumber's avatar
12k
macumber
answered 2015-10-30 09:34:53 -0500
edit flag offensive 0 remove flag delete link

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
add a comment see more comments