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.
What have you tried? Show us what you have so far and what isn’t working.
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.
@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 (32.6 KB)
This is Python Script i used-
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
from Autodesk.Revit.DB import *
from System.Collections.Generic import List
#The inputs to this node will be stored as a list in the IN variables.
elements = UnwrapElement(IN)
elements = [UnwrapElement(IN)]
if isinstance(IN, list):
newlocations = [x.ToXyz() for x in IN]
newlocations = [IN.ToXyz()]
options = CopyPasteOptions()
elementlist = ListElementId
for element,loc in zip(elements,newlocations):
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) newelements.append(newelement.ToDSType(False)) except: newelements.append(None)
#Assign your output to the OUT variable.
OUT = newelements
@JacobSmall 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.
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?
@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 ??
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) fromRooms = UnwrapElement(IN) toRooms = UnwrapElement(IN) 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…
@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”
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.
I think this will guide you.
link for rvt file -
COPY.dyn (34.7 KB)
This is Updated Dynamo file - COPY_1.dyn (68.2 KB)
Please Tell me where Am wrong and how to solve this. Thank you
@Durmus_Cesur Thank you sir, but i unable to find package for Orchid_Object.XYZ node. which package i have to install for this?
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) fromRooms = UnwrapElement(IN) toRooms = UnwrapElement(IN) 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
@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?
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
how to copy multiple elements from one room to multiple rooms ?
COPY items.dyn (83.7 KB)
This script works only for one Destination room. whats wrong in it? please help me?