如何使用 Revit API 获取轴 属性?
How to get axis property with Revit API?
我正在尝试使用 Revit Interactive Python Shell 在 Revit 中旋转对象。我挂断了如何指定旋转轴。我不知道如何用 API 创建一条线,然后在 ElementTransformUtils.RotateElement()
中指定一个轴
RotateElement() 中的第三个参数是轴。我正在创建一条线,但我不确定我是否在 .RotateElement()
的第三个参数中指定了它的轴
当我 运行 这段代码没有任何反应。如果我选择了一堵墙,情况也是如此。如果有任何需要澄清的地方,请告诉我。
谢谢,
import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
def pickobject():
from Autodesk.Revit.UI.Selection import ObjectType
__window__.Hide()
picked = uidoc.Selection.PickObject(ObjectType.Element)
__window__.Show()
__window__.Topmost = True
return picked
#set the active Revit application and document
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
#define a transaction variable and describe the transaction
t = Transaction(doc, 'This is my new transaction')
#start a transaction in the Revit database
t.Start()
#perform some action here...
el = pickobject()
p1 = XYZ(0,0,0)
p2 = XYZ(0,0,1)
myLine = Line.CreateBound(p1, p2)
ElementTransformUtils.RotateElement(doc, el.ElementId, myLine, math.pi / 2)
#commit the transaction to the Revit database
t.Commit()
#close the script window
__window__.Close()
原来我没有正确选择元素或将度数转换为弧度。完成这些操作后,我可以让我选择的元素旋转 90 度。我现在面临的唯一问题是选择元素旋转的原点。
我认为你做错的是角度。
这需要以弧度为单位。在您的示例中,这将是 π/2。
参见 here
一旦 90
度被 0.5 * pi
弧度取代,我认为您的 Python 脚本完全没问题。您可以将它与用于 Creative Workaround to Rotate Elevation Marker in Chunks.
的类似工作示例代码片段进行比较
我正在尝试使用 Revit Interactive Python Shell 在 Revit 中旋转对象。我挂断了如何指定旋转轴。我不知道如何用 API 创建一条线,然后在 ElementTransformUtils.RotateElement()
中指定一个轴RotateElement() 中的第三个参数是轴。我正在创建一条线,但我不确定我是否在 .RotateElement()
的第三个参数中指定了它的轴当我 运行 这段代码没有任何反应。如果我选择了一堵墙,情况也是如此。如果有任何需要澄清的地方,请告诉我。
谢谢,
import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
def pickobject():
from Autodesk.Revit.UI.Selection import ObjectType
__window__.Hide()
picked = uidoc.Selection.PickObject(ObjectType.Element)
__window__.Show()
__window__.Topmost = True
return picked
#set the active Revit application and document
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
#define a transaction variable and describe the transaction
t = Transaction(doc, 'This is my new transaction')
#start a transaction in the Revit database
t.Start()
#perform some action here...
el = pickobject()
p1 = XYZ(0,0,0)
p2 = XYZ(0,0,1)
myLine = Line.CreateBound(p1, p2)
ElementTransformUtils.RotateElement(doc, el.ElementId, myLine, math.pi / 2)
#commit the transaction to the Revit database
t.Commit()
#close the script window
__window__.Close()
原来我没有正确选择元素或将度数转换为弧度。完成这些操作后,我可以让我选择的元素旋转 90 度。我现在面临的唯一问题是选择元素旋转的原点。
我认为你做错的是角度。 这需要以弧度为单位。在您的示例中,这将是 π/2。 参见 here
一旦 90
度被 0.5 * pi
弧度取代,我认为您的 Python 脚本完全没问题。您可以将它与用于 Creative Workaround to Rotate Elevation Marker in Chunks.