Revit Python Pick Object / Select Object

无人久伴 提交于 2019-12-01 10:11:45

问题


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)


回答1:


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.




回答2:


It's because ObjectType is not defined anywhere in that statement's scope:

>>> ObjectType
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ObjectType' is not defined
>>> ObjectType = 12
>>> ObjectType
12

Maybe you forgot an import statement?



来源:https://stackoverflow.com/questions/21296317/revit-python-pick-object-select-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!