Revit Python 拾取对象/选择对象 [英] Revit Python Pick Object / Select Object

查看:46
本文介绍了Revit Python 拾取对象/选择对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编码还很陌生,所以这可能很明显.

为什么我在运行此代码时会收到错误name 'ObjectType' not defined":

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

我正在使用 revit python shell (IronPython)

解决方案

您应该将 ObjectType 导入当前范围:

<预><代码>>>>从 Autodesk.Revit.UI.Selection 导入 ObjectType>>>选择 = uidoc.Selection.PickObject(ObjectType.Element)

我刚刚在 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 拾取对象/选择对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆