First time here? Check our help page!
1

Overwriting a .OSM file with a measure

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.

ParticleSwarm's avatar
389
ParticleSwarm
asked 2018-07-02 12:46:11 -0500, updated 2018-07-02 13:37:41 -0500
edit flag offensive 0 remove flag close merge delete

Comments

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:

https://github.com/aviveiros11/Ruby/b...

Disclaimer: very new to writing measures

ParticleSwarm's avatar ParticleSwarm (2018-07-03 08:17:12 -0500) edit
add a comment see more comments

1 Answer

2

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

https://github.com/aviveiros11/Ruby/b...

# 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.

https://github.com/aviveiros11/Ruby/b...

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

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:

https://github.com/mdahlhausen/scrapp...

# alternative swap
# remove existing objects from model
handles = OpenStudio::UUIDVector.new
model.objects.each do |obj|
  handles << obj.handle
end
model.removeObjects(handles)
# 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.

mdahlhausen's avatar
9.5k
mdahlhausen
answered 2018-07-03 11:22:41 -0500, updated 2018-07-03 14:30:22 -0500
edit flag offensive 0 remove flag delete link

Comments

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

ParticleSwarm's avatar ParticleSwarm (2018-07-03 12:06:02 -0500) edit
add a comment see more comments