hi @dylanpeng, you can try this;
# dynamo version - 1.3.x, 2,x,x
import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
clr.AddReference("RevitNodes")
import System,Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
from Autodesk.DesignScript.Geometry import (Geometry,
Point as pt)
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
elems = IN[0];
# make list
if not isinstance(elems,list):
elems = UnwrapElement([elem])
else:
elems = UnwrapElement(elems)
# output
res = []
# start transaction
TransactionManager.Instance.EnsureInTransaction(doc)
# loop elements
for e in elems:
# level elevation - unit millimeter
elevation = e.Level.Elevation * 304.8
# get geo-objects of the element
geoelem = e.GetGeometryObjectFromReference(Reference(e))
# get enumerator to loop geo-objects
geoobj = geoelem.GetEnumerator()
# loop geo-objector
for obj in geoobj:
# convert to dynamo type
room_geometry = obj.ToProtoType()
# get the centroid of the element
point = room_geometry.Centroid()
# create location point with level elevation
center = pt.ByCoordinates(point.X,point.Y,elevation)
# current element location
current = e.Location.Point
# point convert to revit and minus from current location
newloc = center.ToXyz() - current
# move to new location
e.Location.Move(newloc)
# transaction done
TransactionManager.Instance.TransactionTaskDone()
# output
OUT = elems