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

Adding osm objects from one model to another

asked 2018-08-22 20:38:18 -0600

antonszilasi gravatar image

I would like to add objects from one model to another. I know how to load existing osms using the code below -

# load the test model
translator =
path = + "/my_test_model_test_input.osm")
model = translator.loadModel(path)
assert((not model.empty?))
model = model.get

however once I load two models how can add the objects from one model to another?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-23 02:18:06 -0600

updated 2018-08-24 02:36:22 -0600

Initiate two models like you put above, let's call them model_source and model_target, and let's say you want to transfer a Water heater from source to target:

wh = model_source.getWaterHeaterMixeds[0]


To answer your comment about adding everything, this is no code that I'm aware of to do that really, so you should expect some problems depending on what you have in your source model. The problem is really about the relationships between objects and the order in which they are cloned. That probably sounds pretty abstract, but let me give you an example.

I'm creating a model with one space, that has a SpaceType assigned to it. I want to "move" that to another model:

m =
sp =
s =

m2 =

You might be tempted to just do m.modelObjects.each {|o| o.clone(m2)}, but you're likely going to have problems:

[utilities.idf.Workspace] <-1> Renamed Object of type 'OS:SpaceType' and named 'Space Type 1' to 'Space Type 2' to avoid a name conflict upon WorkspaceObject addition.

Why did we get this message? Because underneath what it really did is this:

# Clone the space, which will also clone its SpaceType
# Note at this point this will return false!

# Clone the spaceType, except its already been cloned so there's also a space type with the same name in the target model, so it'll get duplicated.

On the other hand, if you do it the other way round, it'll do just fine:

m2 =

Other problems you may encounter is that some clone methods are perhaps (if it is, that's recent) not 100% working (airloop.clone etc).

If the only stuff you have in the source models are spaces, zones, and geometry, then perhaps m.getBuilding.clone(m2) would work. You can see the source code at Building.cpp, seems it's handling geometry related stuff quite well, but doesn't affect any loops.

edit flag offensive delete link more


@Julien Marrec many thanks for the answer however I am interested in adding the whole of one model to another no need to pick certain objects - whats the code for doing that?

antonszilasi gravatar imageantonszilasi ( 2018-08-23 17:56:18 -0600 )edit

FYI there's some interesting code in ModelMerger but that's not going to work for you.

Julien Marrec gravatar imageJulien Marrec ( 2018-08-24 04:45:46 -0600 )edit

Your Answer

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

Add Answer


Question Tools



Asked: 2018-08-22 20:38:18 -0600

Seen: 121 times

Last updated: Aug 24