Moving multiple elements in XYZ

Good afternoon

I found a python script on the Internet.

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?

1 Like

Hi @status_diamond ,

The easiest way to solve this is by wrapping the Python script into a Custom Node.
Then you just have to set the Custom Node input to @L2.

Do you know Custom Node for moving elements along XYZ? I can’t find. Thanks.

I meant that you’ll have to do that yourself.

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.

I see,

Check out this guide on how to create a Custom Node:
https://primer.dynamobim.org/10_Custom-Nodes/10_Custom-Nodes.html

Try this

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

Thanks! It works!

we can use directly this method for a list of element

  • ElementTransformUtils.MoveElements
2 Likes

Ah, yeah, fair enough!