# Copy Elements or Group From one room to Another

**URL:** <https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946>\
**Category:** Developers\
**Tags:** revit, python, dynamo\
**Created:** [September 23, 2019, 8:51am UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946 "2019-09-23T08:51:35Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 23, 2019, 8:51am UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/1 "2019-09-23T08:51:35Z")

</div>

Am trying to Copy elements from One room to Another. please help me how can i do this using python script, am New to Dynamo and Revit.

---

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 23, 2019, 9:07am UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/2 "2019-09-23T09:07:02Z")

</div>

@jacob.small @maciek.glowka can you help me with this problem?

---

<div class="post-metadata">

**Author:** ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)\
**Post date:** [September 23, 2019, 12:02pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/3 "2019-09-23T12:02:29Z")

</div>

What have you tried? Show us what you have so far and what isn’t working.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [September 23, 2019, 12:03pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/4 "2019-09-23T12:03:34Z")

</div>

I don’t have a data set to play with, so no I cannot.

If you upload a sample rvt and the dyn you are using to this point and I will try and find time - I do have two other forum users to help first though.

---

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 23, 2019, 12:28pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/5 "2019-09-23T12:28:20Z")

</div>

@SeanP i want to copy elements (like furniture’s, bed) or group of elements from one room to another room using python script.

Here is Dynamo file i created (it’s Working But manually for four rooms only, didn’t position exact location) [COPY.dyn](https://forum.dynamobim.com/uploads/short-url/zmG5XG3531ozyasMWgC1sDUtqal.dyn) (32.6 KB)

This is Python Script i used-

import clr

clr.AddReference(“RevitServices”)  
import RevitServices  
from RevitServices.Persistence import DocumentManager  
from RevitServices.Transactions import TransactionManager  
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference(“RevitAPI”)  
import Autodesk  
from Autodesk.Revit.DB import \*

clr.AddReference(“RevitNodes”)  
import Revit  
clr.ImportExtensions(Revit.Elements)  
clr.ImportExtensions(Revit.GeometryConversion)

from System.Collections.Generic import List  
#The inputs to this node will be stored as a list in the IN variables.  
if isinstance(IN[0],list):  
elements = UnwrapElement(IN[0])  
else:  
elements = [UnwrapElement(IN[0])]  
if isinstance(IN[1], list):  
newlocations = [x.ToXyz() for x in IN[1]]  
else:  
newlocations = [IN[1].ToXyz()]

newelements =

options = CopyPasteOptions()  
elementlist = ListElementId

TransactionManager.Instance.EnsureInTransaction(doc)  
for element,loc in zip(elements,newlocations):  
try:  
oldloc = element.Location.Point

```
	elementlist.Add(element.Id)
	OffsetZ = (oldloc.Z - loc.Z)*-1
	OffsetX = (oldloc.X - loc.X)*-1
	OffsetY = (oldloc.Y - loc.Y)*-1
	direction = XYZ(OffsetX,OffsetY,OffsetZ)
	trans = Transform.CreateTranslation(direction)
	newelementId = ElementTransformUtils.CopyElements(doc,elementlist,doc,trans,options)
	elementlist.Clear()
	newelement = doc.GetElement(newelementId[0])
	newelements.append(newelement.ToDSType(False))
except:
	newelements.append(None)

```

TransactionManager.Instance.TransactionTaskDone()  
#Assign your output to the OUT variable.  
OUT = newelements

---

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 23, 2019, 12:39pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/6 "2019-09-23T12:39:21Z")

</div>

@jacob.small Thank for your reply sir. my rvt file is too big to upload. i just create a four room block where i try to copy elements from one room to another.

---

<div class="post-metadata">

**Author:** ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)\
**Post date:** [September 23, 2019, 12:55pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/7 "2019-09-23T12:55:53Z")

</div>

Are the rooms all the same? How are you generating the new points for the transform? Are you using room center or corner? Seems like you have the foundation of the graph, just need to work out the geometry. How are you doing it now?

---

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 23, 2019, 1:16pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/8 "2019-09-23T13:16:51Z")

</div>

@SeanP yes sir, Initially am testing this script on same rooms. i just find position of elements in room by Element.GetLocation node, but i fail to get room exact location in another room. i don’t know how to do it now.  
i think by finding curves of rooms and vector, it will be done, please tell me how can i do that ??

---

<div class="post-metadata">

**Author:** ![maciek.glowka](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/maciek.glowka/32/70695_2.png) [@maciek.glowka](https://forum.dynamobim.com/u/maciek.glowka)\
**Post date:** [September 23, 2019, 1:37pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/9 "2019-09-23T13:37:23Z")

</div>

Hi,

you can simplify your script a bit like so:

```
import clr

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager

#The inputs to this node will be stored as a list in the IN variables.
elements = UnwrapElement(IN[0])
fromRooms = UnwrapElement(IN[1])
toRooms = UnwrapElement(IN[2])

output = []
doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(doc)

for e, r0, r1 in zip(elements,fromRooms,toRooms):
	l0 = r0.Location.Point
	l1 = r1.Location.Point	
	d = l1-l0
	
	id = ElementTransformUtils.CopyElement(doc,e.Id,d)
	output.append(id)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = output

```

However it assumes at the moment that room centres are in the same spot (in relation to the boundary). Which I guess is not the case - reading above messages.  
I will try later to update the script to calculate the geometrical centre…

---

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 23, 2019, 1:54pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/10 "2019-09-23T13:54:57Z")

</div>

@maciek.glowka Thank you sir, i Try python script provided by you but it gives error with warning.  
“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.  
Traceback (most recent call last):  
File “”, line 21, in   
TypeError: FamilyInstance is not iterable”

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [September 23, 2019, 2:06pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/11 "2019-09-23T14:06:41Z")

</div>

We really need you to post the RVT and your DYN - otherwise this is a game of ‘guess the lucky number’ for what your intended base level condition and inputs are, and if we guess wrong it doesn’t work for you and we have to revisit our effort.

If the files are too big to host here use a service like google drive, onedrive, box, dropbox, etc.

Thanks for understanding. 🙂

---

<div class="post-metadata">

**Author:** ![Durmus\_Cesur](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/durmus_cesur/32/62638_2.png) [@Durmus\_Cesur](https://forum.dynamobim.com/u/Durmus_Cesur)\
**Post date:** [September 23, 2019, 2:58pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/12 "2019-09-23T14:58:37Z")

</div>

Hi,

I think this will guide you.

> [@Placing model group by name?](https://forum.dynamobim.com/t/placing-model-group-by-name/38596/2):
>
> Hi, It works smoothly on me. The only thing you need is Xyz, the dots and the rest of the code. Previously @Konrad_K_Sobon had done a study on this. I’m adding it to the council to give the acclaimed.[How to create a Detail Group in specific View?](https://forum.dynamobim.com/t/how-to-create-a-detail-group-in-specific-view/30577/8) Also to see what is needed to create the API [https://www.revitapidocs.com/2017/586d4f2e-0985-2d0b-dbb7-ea6d2f704336.htm](https://www.revitapidocs.com/2017/586d4f2e-0985-2d0b-dbb7-ea6d2f704336.htm) ekliyorum. [1] import clr clr.AddReference("RevitNodes") import Revit clr.ImportExtensions(Revit.Elements) # Import DocumentMan…

Durmus

---

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 24, 2019, 4:51am UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/13 "2019-09-24T04:51:23Z")

</div>

@jacob.small  
link for rvt file -

> **[copy.rvt](https://drive.google.com/file/d/1sRxOoyVSC6YyPX7Ka-xtPnrV4Zmy7N4f/view?usp=sharing)**
>
> Google Drive file.

[COPY.dyn](https://forum.dynamobim.com/uploads/short-url/nPjd2ZH0PZCrcAYrqY4dnfbNLoS.dyn) (34.7 KB)

This is Updated Dynamo file - [COPY\_1.dyn](https://forum.dynamobim.com/uploads/short-url/nqs4SgLhcelsH2BrgeN9VNJRX3A.dyn) (68.2 KB)

Please Tell me where Am wrong and how to solve this. Thank you

---

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 24, 2019, 5:45am UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/14 "2019-09-24T05:45:36Z")

</div>

@Durmus_Cesur Thank you sir, but i unable to find package for **Orchid\_Object.XYZ** node. which package i have to install for this?

---

<div class="post-metadata">

**Author:** ![maciek.glowka](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/maciek.glowka/32/70695_2.png) [@maciek.glowka](https://forum.dynamobim.com/u/maciek.glowka)\
**Post date:** [September 24, 2019, 7:56am UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/15 "2019-09-24T07:56:38Z")

</div>

Hi,

you get the error because the script expects lists as input…  
-first list is a list of elements to copy  
-second is a list of source rooms  
-third is a list of target rooms

please also check the script below - it is using bounding boxes (the bottom left - Min corner) rather than room centre points - might be working better

```
import clr

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager

#The inputs to this node will be stored as a list in the IN variables.
elements = UnwrapElement(IN[0])
fromRooms = UnwrapElement(IN[1])
toRooms = UnwrapElement(IN[2])

output = []
doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(doc)

for e, r0, r1 in zip(elements,fromRooms,toRooms):
	#l0 = r0.Location.Point
	#l1 = r1.Location.Point
	bb0 = r0.get_BoundingBox(None)
	bb1 = r1.get_BoundingBox(None)
	
	#d = l1-l0
	d = bb1.Min - bb0.Min
	
	id = ElementTransformUtils.CopyElement(doc,e.Id,d)
	output.append(id)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = output
```

---

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 24, 2019, 9:11am UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/16 "2019-09-24T09:11:56Z")

</div>

@maciek.glowka Thank you so much sir, It works. Even your Above code also Works. But, it only Copy one element at time, For Multiple elements?

---

<div class="post-metadata">

**Author:** ![maciek.glowka](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/maciek.glowka/32/70695_2.png) [@maciek.glowka](https://forum.dynamobim.com/u/maciek.glowka)\
**Post date:** [September 24, 2019, 1:55pm UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/17 "2019-09-24T13:55:34Z")

</div>

Well it does work for multiple elements as it is accepting lists on input.  
You just have to make sure the lists are correctly set beforehand.  
For each copied element you have to make sure there is a fromRoom and toRoom in other inputs.  
I am not very proficient with lists manipulations in Dynamo myself, but I am pretty sure somebody here will be able to help you with that 🙂

---

<div class="post-metadata">

**Author:** ![sonu41](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sonu41](https://forum.dynamobim.com/u/sonu41)\
**Post date:** [September 26, 2019, 8:53am UTC](https://forum.dynamobim.com/t/copy-elements-or-group-from-one-room-to-another/40946/18 "2019-09-26T08:53:49Z")

</div>

how to copy multiple elements from one room to multiple rooms ?  
[COPY items.dyn](https://forum.dynamobim.com/uploads/short-url/kELZWqz7bGOf5XpsiE1Jlxv4GRd.dyn) (83.7 KB)  
This script works only for one Destination room. whats wrong in it? please help me?
