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

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

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

1 Answer

Sort by ยป oldest newest most voted
2

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:

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.

edit flag offensive delete link more

Comments

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

Training Workshops

Careers

Question Tools

1 follower

Stats

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

Seen: 138 times

Last updated: Jul 03 '18