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

use openstudio API to clone object to the same parent object

asked 2020-09-17 14:58:32 -0500

xchen's avatar

I am using ModelObject:Clone to copy subsurfaces from a different osm model but noticed that it lost the hosting parent object in the new model, i.e. those subsurfaces no longer have it's surface, although the surface, subsurface name and handles are the same between the two models.

Is there a way to copy the subsurface only but keep the same parent object in the model?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-09-17 17:03:09 -0500

updated 2020-09-17 17:05:40 -0500

When you clone an OpenStudio object within the same model or to another model it should always generate a unique new 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, 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
edit flag offensive delete link more

Comments

thanks, setSurface works for me.

xchen's avatar xchen  ( 2020-09-17 20:33:45 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Careers

Question Tools

1 follower

Stats

Asked: 2020-09-17 14:58:32 -0500

Seen: 85 times

Last updated: Sep 17 '20