我正在尝试围绕其中心点旋转 Revit 元素。为此,我需要选择一个 Revit 元素并找到它的中心点,然后使用该元素中心点的坐标创建一条线。
完成此操作的最佳方法是将 Revit 元素包装在边界框中,然后找到该框的中心。我的问题是我不确定如何做到这一点。
我正在使用 pyRevit (惊人的工具),我被困在如何使用边界框包装选定元素或检索其现有边界框。
任何帮助将不胜感激!我真的很想学习 Revit API 并了解一切是如何工作的。我正在取得进展,但还有很多事情要解开。
def pickobject():
from Autodesk.Revit.UI.Selection import ObjectType
#define the active Revit application and document
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
#define a transaction variable and describe the transaction
t = Transaction(doc, 'This is my new transaction')
# Begin new transaction
t.Start()
# Select an element in Revit
picked = uidoc.Selection.PickObject(ObjectType.Element, "Select something.")
### ?????????? ###
# Get bounding box of selected element.
picked_bb = BoundingBoxXYZ(picked)
# Get max and min points of bounding box.
picked_bb_max = picked_bb.Max
picked_bb_min = picked_bb.Min
# Get center point between max and min points of bounding box.
picked_bb_center = (picked_bb_max + picked_bb_min) / 2
### ?????????? ###
# Close the transaction
t.Commit()
return picked, picked_bb_center
提前感谢您查看我到目前为止所拥有的内容。如果有任何需要进一步澄清的地方,请告诉我!
编辑:
@CyrilWaechter
我想你是对的。使用 LocationPoint 可能更有意义。我查看了您链接的脚本(谢谢顺便说一句!),我尝试在我的代码中实现这一部分。
transform = doc.GetElement(picked.ElementId).GetTransform()
我正在通过此语句传递 ElementId,但出现错误,“Wall”对象没有属性“GetTransform”。你能帮我理解这个吗?
编辑2:感谢@JeremyTammik 和@CyrilWaechter,您的见解帮助我了解了哪里出错了。虽然我仍然觉得 Revit API 中的某些属性不明确,但我能够让我的代码正确执行。我将在下面发布我能够工作的代码。