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

Revision history [back]

When you clone an OpenStudio object within the same model or to another model it should always generate a unique new handle.

If you for example have a space named asdf in model_1 and clone it into model_2 which already has a space named asdf the cloned space won't overwrite the existing one, but will rename the cloned space something like asdf 1. I have worked a measure to merge spaces from external model into the active model that is meant to allow updated spaces to be brought into a model that already has HVAC system. There has been development to make this more robust and support merging in mechanical systems as well. What you are describing is a situation to bring in updated fenestration to an existing model. The measure could be updated to support that but doesn't right now. Below is some code that should be pretty close to what you want.

# store parent surface name, will have a surface typically so I didn't check if initialized
sub_surf_to_clone = model_2.getSubSuraces.first
surf_name = sub_surf_to_clone.surface.get.name.to_s 

# clone sub surface to from model_2 into model
cloned_sub_surface = sub_surf_to_clone.clone(model)

# todo - you may want to clear out existing sub-surfaces from that surface since they may overlap with what is being cloned from model_2

# find parent of same name in model, if found assign cloned sub_surface to it
parent_surf = model.getSurfaceByName(surf_name)
if parent_surf.is_initialized
  parent_surf = parent_surf.get
  cloned_sub_surface.setSurface(parent_surf)
else
  # didn't find surface by that name, nothing to do.
end

When you clone an OpenStudio object within the same model or to another model it should always generate a unique new handle.

If you for example handle. Additionally, if you have a space named asdf in model_1 and clone it into model_2 which already has a space named asdf the cloned space won't overwrite the existing one, but will rename the cloned space something like asdf 1. I have worked a measure to merge spaces from external model into the active model that is meant to allow updated spaces to be brought into a model that already has HVAC system. system, that bypasses the behavior desscribed above, by using space name to identify which spaces are the same. There has been some development to make this more robust and support merging in mechanical systems as well. What you are describing is a situation to bring in updated fenestration to an existing model. The measure could be updated to support that but doesn't right now. Below is some code that should be pretty close to what you want.

# store parent surface name, will have a surface typically so I didn't check if initialized
sub_surf_to_clone = model_2.getSubSuraces.first
surf_name = sub_surf_to_clone.surface.get.name.to_s 

# clone sub surface to from model_2 into model
cloned_sub_surface = sub_surf_to_clone.clone(model)

# todo - you may want to clear out existing sub-surfaces from that surface since they may overlap with what is being cloned from model_2

# find parent of same name in model, if found assign cloned sub_surface to it
parent_surf = model.getSurfaceByName(surf_name)
if parent_surf.is_initialized
  parent_surf = parent_surf.get
  cloned_sub_surface.setSurface(parent_surf)
else
  # didn't find surface by that name, nothing to do.
end