【问题标题】:How to get axis property with Revit API?如何使用 Revit API 获取轴属性?
【发布时间】:2018-12-11 01:37:12
【问题描述】:

我正在尝试使用 Revit 交互式 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 度。我现在面临的唯一问题是选择元素旋转的原点。

【问题讨论】:

    标签: python api revit-api revit


    【解决方案1】:

    我认为你做错的是角度。 这需要以弧度表示。在您的示例中,这将是 π/2。 见here

    【讨论】:

    • 您好 Jan,感谢您抽出宝贵时间研究此问题。我将角度更改为 math.pi / 2。但是,墙壁仍然没有旋转。 Rotate Element 方法是否仅适用于基本几何体?
    • @ChristianGentry 我看到您的轮换工作正常,但正在为轮换原点而苦苦挣扎?如果要更改,只需将代码中 p1 和 p2 的 X 和 Y 坐标更改为原点即可。
    【解决方案2】:

    一旦90 度被0.5 * pi 弧度替换,您的Python 脚本对我来说完全没问题。您可以将其与用于Creative Workaround to Rotate Elevation Marker in Chunks 的类似 sn-p 工作示例代码进行比较。

    【讨论】:

    • 谢谢杰里米!它不起作用的原因是因为我没有转换为弧度,而且我也没有正确选择元素。现在我唯一的问题是指定旋转原点。
    • 很高兴听到。 myLine定义的旋转轴定义了旋转的原点和方向。
    猜你喜欢
    • 2013-01-07
    • 2020-03-05
    • 2019-09-21
    • 2020-06-30
    • 2014-09-18
    • 2021-03-28
    • 2021-03-27
    • 2020-04-20
    • 2018-03-30
    相关资源
    最近更新 更多