【发布时间】:2019-06-16 22:25:07
【问题描述】:
我在编写让 med 选择我选择的第一个元素的脚本时遇到问题。这对我很有用,因为我从时间表中选择了正确的 Air Terminal(在那里我可以看到我想要使用的类似气流),并从选择中使用命令 Create Similar。 The trouble is that this command does not work when multiple elements are selected.因此,我想要列表中的第一个对象。 这是我正在尝试的代码:
from Autodesk.Revit.UI.Selection.Selection import SetElementIds
from System.Collections.Generic import List
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]
sel=[]
for i in selection:
sel.append(i.Id)
uidoc.Selection.SetElementIds(List[ElementId](sel[0]))
这将返回以下错误消息:
Exception : Microsoft.Scripting.ArgumentTypeException: expected int, got ElementId 好的,那我试试替换
uidoc.Selection.SetElementIds(List[ElementId](sel[0]))
与
uidoc.Selection.SetElementIds(List[ElementId](sel[0].IntegerValue))
This seems to work, but selection is not modified
我刚刚开始编写 RPS 脚本,但我希望有人能告诉我我在这里做错了什么,即使它很明显。
谢谢。 凯尔
编辑: 谢谢杰里米,为我解决了这个问题!诀窍是生成一个列表,而不是 python 列表。 .add 方法是我没有得到的。
如果有人感兴趣,最终代码:
from Autodesk.Revit.UI.Selection.Selection import SetElementIds
from System.Collections.Generic import List
from Autodesk.Revit.DB import ElementId
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = [ doc.GetElement( elId ) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds() ]
sel=[]
for i in selection:
sel.append(i.Id)
ids=List[ElementId](1)
ids.Add(sel[0])
uidoc.Selection.SetElementIds(ids)
【问题讨论】:
标签: revit-api revitpythonshell pyrevit