常見問題:缺乏的庫引用,Autodesk.Revitshell
# AlexDong
# 1220274707@qq.comapp
import mathui
selection = [doc.GetElement(x) for x in uidoc.Selection.GetElementIds()]orm
def rotateSelectedElement(degrees_to_rotate,add):element
from Autodesk.Revit.UI.Selection import ObjectTypeget
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocumentit
t = Transaction(doc, 'This is my new transaction')io
converted_value = float(degrees_to_rotate) * (math.pi / 180.0)form
t.Start()import
el = selection[add].Id
el_ID = doc.GetElement(el)
el_bb = el_ID.get_BoundingBox(doc.ActiveView)
el_bb_max = el_bb.Max
el_bb_min = el_bb.Min
el_bb_center = (el_bb_max + el_bb_min) / 2
p1 = XYZ(el_bb_center[0], el_bb_center[1], 0)
p2 = XYZ(el_bb_center[0], el_bb_center[1], 1)
myLine = Line.CreateBound(p1, p2)
# Rotate the selected element.
ElementTransformUtils.RotateElement(doc, el, myLine, converted_value)
# Close the transaction
if t.Commit() != TransactionStatus.Committed:
#print("t --RollBack")
t.RollBack()
add=0for aa in selection: #print(aa) rotateSelectedElement(45,add) add += 1#t.Commit()