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.
@jacob.small @maciek.glowka can you help me with this problem?
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-
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
@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.
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 ??
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ā¦
@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.
Hi,
I think this will guide you.
Durmus
@jacob.small
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?
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
@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?