如何使用Revit API获取轴属性?

时间:2018-12-10 07:44:06

标签: python api revit-api revit

我正在尝试使用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 个答案:

答案 0 :(得分:1)

我认为您在做错的是角度。 这必须以弧度为单位。在您的示例中,该值为π/ 2。 参见here

答案 1 :(得分:1)

90度替换为0.5 * pi弧度后,您的Python脚本在我看来就可以了。您可以将其与用于Creative Workaround to Rotate Elevation Marker in Chunks的工作示例代码的类似片段进行比较。