import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variable.
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
dataEnteringNode = IN
elementId = IN[0].Id
TransactionManager.Instance.EnsureInTransaction(doc)
ElementTransformUtils.MoveElement(doc,ElementId(elementId),XYZ(IN[1],IN[2],IN[3]))
TransactionManager.Instance.TransactionTaskDone()
# Assign your output to the OUT variable.
OUT = 0
This script works wonderfully if IN[0] is given one element.
How to make it work when multiple elements are fed into the input?
However, for just moving elements you don’t need a custom Python script, just the Element.Location / Element.SetLocation nodes. Just make sure the new location is the old location + your translation.
I have already tried to move elements by changing their coordinates. But each element has its own parameter responsible for its position.
Plus, with simple nodes like this Element.Location / Element.SetLocation problem is not solvable.
import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variable.
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
dataEnteringNode = IN
def tolist(obj):
if hasattr(obj, "__iter__"):
return obj
else:
return [obj]
elems = tolist(IN[0])
elems = [UnwrapElement(x) for x in elems]
TransactionManager.Instance.EnsureInTransaction(doc)
[ElementTransformUtils.MoveElement(doc,e.Id,XYZ(IN[1],IN[2],IN[3])) for e in elems]
TransactionManager.Instance.TransactionTaskDone()
# Assign your output to the OUT variable.
OUT = 0