问题描述
我对编码还很陌生,所以这可能很明显.
为什么我在运行此代码时会收到错误name 'ObjectType' not defined":
picked = uidoc.Selection.PickObject(ObjectType.Element)
我正在使用 revit python shell (IronPython)
您应该将 ObjectType
导入当前范围:
我刚刚在 RevitPythonShell 中尝试了这个,并注意到它不起作用,因为 shell 仍然在前台.因此,这种技术适用于您添加到功能区的脚本,但不能直接从 shell 中使用...我还不太确定如何解决这个问题.对不起.
使用这样的函数来实现这一点:
def pickobject():从 Autodesk.Revit.UI.Selection 导入 ObjectType__window__.Hide()选择 = uidoc.Selection.PickObject(ObjectType.Element)__window__.Show()__window__.Topmost = 真回采
您可以通过将其粘贴到底部的编辑器窗格中并按 F5 或将其添加到您的 Init-Script 或其他任何方式来运行它.然后在需要选择元素时调用 pickobject()
.
I'm fairly new to coding, so this might be obvious.
Why do I get an error "name 'ObjectType' not defined" when I run this code:
picked = uidoc.Selection.PickObject(ObjectType.Element)
I'm using revit python shell (IronPython)
You should import ObjectType
into the current scope:
>>> from Autodesk.Revit.UI.Selection import ObjectType
>>> picked = uidoc.Selection.PickObject(ObjectType.Element)
I have just tried this out in the RevitPythonShell and have noticed, that it doesn't work, because the shell is still in the foreground. So, this technique will work for scripts that you add to the Ribbon, but not directly from the shell... I'm not quite sure how to fix this yet. Sorry.
EDIT: Use a function like this one to do the trick:
def pickobject():
from Autodesk.Revit.UI.Selection import ObjectType
__window__.Hide()
picked = uidoc.Selection.PickObject(ObjectType.Element)
__window__.Show()
__window__.Topmost = True
return picked
You can run this by pasting it into the editor pane at the bottom and hitting F5 or adding it to your Init-Script or whatever. And then just call pickobject()
when you need to pick an Element.
这篇关于Revit Python 拾取对象/选择对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!