简体   繁体   English

Revit Python选择对象/选择对象

[英]Revit Python Pick Object / Select Object

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: 运行此代码时,为什么会出现错误“未定义名称'ObjectType'”:

picked = uidoc.Selection.PickObject(ObjectType.Element)

I'm using revit python shell (IronPython) 我正在使用revit python shell(IronPython)

You should import ObjectType into the current scope: 您应该将ObjectType导入当前范围:

>>> 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. 我刚刚在RevitPythonShell中进行了尝试,并注意到它不起作用,因为外壳仍在前台。 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. 因此,该技术将适用于您添加到功能区中的脚本,但不能直接从Shell中添加...我还不确定如何解决此问题。 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. 您可以通过将其粘贴到底部的编辑器窗格中并单击F5或将其添加到您的Init-Script或任何其他方式来运行它。 And then just call pickobject() when you need to pick an Element. 然后,当您需要拾取元素时,只需调用pickobject()即可。

It's because ObjectType is not defined anywhere in that statement's scope: 这是因为在该语句范围内的任何地方都没有定义ObjectType

>>> 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? 也许您忘记了进口声明?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM