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

Overwriting a .OSM file with a measure

asked 2018-07-02 12:46:11 -0500

ParticleSwarm's avatar

updated 2018-07-02 13:37:41 -0500

I was wondering if it was possible to have a measure to load an existing .osm that would re - write the existing one to hold the loaded data.

Similar to the DOE prototype structure, be able to apply a measure that overwrites the existing and replaces with another .osm model.

I have a measure that takes all of the data for an existing osm and stores it in a new model, but when I accept the changes in the apply measure now section, it remains untouched.

image description

I am able to get it to this point and everything seems in order.

edit retag flag offensive close merge delete


could you post a link to the measure? It's possible you are loading the new model but never assign it to the right model variable.

mdahlhausen's avatar mdahlhausen  ( 2018-07-02 18:10:23 -0500 )edit

@mdahlhausen Here is the link to the full measure:

Disclaimer: very new to writing measures

ParticleSwarm's avatar ParticleSwarm  ( 2018-07-03 08:17:12 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-07-03 11:22:41 -0500

updated 2018-07-03 14:30:22 -0500

When the measure runs, it acts on the model you pass in with the model variable in the run function definition:

# define what happens when the measure is run 
def run(model, runner, user_arguments)  
  super(model, runner, user_arguments)

This variable is saved as model. If you want the measure to apply to this model, you can't redefine this variable later in the measure.

if OpenStudio::exists(model_path)
  model = translator.loadModel(model_path)
  if model.empty?
    puts "Version translation failed for #{model_path}"
    model = model.get

Here you redefine the model variable. You are now no longer acting on the original model. No changes were made to the original model you passed in with the variable model, so the measure doesn't do anything.

What you want to do is replace all the objects in the old model with objects in the new model, leaving the original model variable intact.

Something like:

# alternative swap
# remove existing objects from model
handles =
model.objects.each do |obj|
  handles << obj.handle
# add new file to empty model
model.addObjects( newModel.toIdfFile.objects )

You can use the ReplaceModel measure in the link above; it's an NREL development measure not formally published on BCL.

Note that you may need to remove or reset design days and/or the weather file.

edit flag offensive delete link more


This worked great! Thank you so much for the guidance!

ParticleSwarm's avatar ParticleSwarm  ( 2018-07-03 12:06:02 -0500 )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: 2018-07-02 12:46:11 -0500

Seen: 138 times

Last updated: Jul 03 '18