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

adding IDF variable reporting code to OS via measure?

asked 2015-07-23 12:28:43 -0600

Nick N gravatar image

updated 2017-08-22 10:46:30 -0600

I have a swath of e+ output:variables I'd like to add to the reporting of an OS run. Does anyone has a favorite way of doing that?

Currently I'm post-processing by simulating the OS model, then adding my variables (IDF code) to the generated out.idf, then re-running the out.idf. I'm sure there's a slicker method. I have used the measure: addOutputVariable in the past, but it seems cumbersome to repeat that more than a few times.

Is there perhaps another measure out there that people use just to load in IDF code to the OSM, pre-run? This might be an excuse to write my first measure, but I'd be surprised if I'm the first to think this is a good idea.

Or, if there's an even better (and obvious) workflow, I'd be interested in that, too.

edit retag flag offensive close merge delete


Looks like a duplicate of this post

David Goldwasser gravatar image David Goldwasser  ( 2015-07-23 12:51:45 -0600 )edit

As far as writing a measure to inject raw IDF text, you can ask that in a different question, but for the short answer look at this tariff measure. It grabs an IDF file out of the measures resource folder and imports specific types of IDF objects. It could import all IDF objects and could pull them in from any file on your computer vs. the resources directory (although that last part is problematic for cloud simulations).

David Goldwasser gravatar image David Goldwasser  ( 2015-07-23 12:54:07 -0600 )edit

@David Goldwasser it seems to me @Nick N is asking a different question than the one you linked, since he mentions having used the Add Output Variable measure, but is seeking an alternative to that workflow.

Eric Ringold gravatar image Eric Ringold  ( 2015-07-23 13:24:27 -0600 )edit

Indeed - we're taking the variables output from the simulation run and feeding them into another environment for modeling of a different (building-integrated) system. I had thought about that tariff measure earlier, but hadn't had the chance yet to learn if it was generally pulling in IDF code, or if it was selecting specific objects (which you mention it does). I'll look into it--either way, a good place to start.

Nick N gravatar image Nick N  ( 2015-07-23 15:16:23 -0600 )edit

Turns out I add everything from the file. I think I was just being selective in the arguments section to populate a choice list of possible tariffs by fuel.

   # add everything from the file
David Goldwasser gravatar image David Goldwasser  ( 2015-07-23 16:21:55 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-23 13:07:13 -0600

updated 2015-07-23 13:27:27 -0600

You can add each variable in the measure tab with multiple 'Add Ouput Variable' measures, but this can get kind of tedious. Instead, if you have all your favorite Output:Variable objects loaded in an .idf file called outputs.idf, you can write an OpenStudio measure with that file in the measure folder in a 'resources' subdirectory. Now in your measure, you can load that idf into an OpenStudio workspace with

library = OpenStudio:Workspace:load("#{File.dirname(__FILE__)}/resources/outputs.idf").get

then translate this idf to osm using the Reverse Translator (which will translate Output:Variable objects):

rt =
library_model = rt.translateWorkspace(library)

Now all you have to do is get all the output variables from the library model, and add them to your model:

#get variables from library model
vars = library_model.getOutputVariables

#loop through each variable and add that variable to the model
vars.each do |var|
  variable_name = var.variableName
  newVariable =,model)

You can add a measure argument to choose a reporting frequency, and add newVariable.setReportingFrequency(reporting_frequency) inside the loop above. Now you have one measure to add whatever number of output variables that you'd like, with no need to fuss in your model's idf.

edit flag offensive delete link more


Thanks @Eric Ringold! I haven't written any measures yet; if I put this one together, I still won't have, really, because you just laid it all out in its practical entirety. I'll compare these snippets to the tariff measure I was looking at, that @David Goldwasser mentioned, and work it out.

Nick N gravatar image Nick N  ( 2015-07-23 15:26:17 -0600 )edit

It's different from the tariff measure that David linked, by using the built-in OpenStudio reverse translator function in an OpenStudio measure to make openstudio::model::OutputVariable objects from idf code, rather than injecting the idf strings into the already-translated idf file that OpenStudio creates. I found this way to be a little simpler than the EnergyPlus measure way.

Eric Ringold gravatar image Eric Ringold  ( 2015-07-23 15:37:58 -0600 )edit

@Nick N if you haven't already, read the Measure Writing Guide for a good introduction to measures.

MatthewSteen gravatar image MatthewSteen  ( 2015-07-23 18:52:30 -0600 )edit

Your Answer

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

Add Answer


Question Tools

1 follower


Asked: 2015-07-23 12:28:43 -0600

Seen: 206 times

Last updated: Aug 22 '17