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]
wh.clone(model_target)
Edit:
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 = Model.new
sp = SpaceType.new(m)
s = Space.new(m)
s.setSpaceType(sp)
m2 = Model.new
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
s.clone(m2)
# Note at this point this will return false!
m2.getSpaces[0].spaceType.empty?
# 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.
sp.clone(m2)
On the other hand, if you do it the other way round, it'll do just fine:
m2 = Model.new
sp.clone(m2)
s.clone(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.