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

Revision history [back]

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/blob/master/load_openstudio_model/measure.rb#L50

# 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 to the measure to apply to this model, you can't redefine this variable later in the measure.

https://github.com/aviveiros11/Ruby/blob/master/load_openstudio_model/measure.rb#L77-#L83

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/scrappEplus/blob/master/OpenStudio/Measures/ReplaceModel/measure.rb#L107-L115

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

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/blob/master/load_openstudio_model/measure.rb#L50

# 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 to the measure to apply to this model, you can't redefine this variable later in the measure.

https://github.com/aviveiros11/Ruby/blob/master/load_openstudio_model/measure.rb#L77-#L83

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/scrappEplus/blob/master/OpenStudio/Measures/ReplaceModel/measure.rb#L107-L115

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