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

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

问题描述

我是相当新的编码,所以这可能是显而易见的。

I'm fairly new to coding, so this might be obvious.

为什么我得到一个错误名称对象类型没有定义当我运行这个code:

Why do I get an error "name 'ObjectType' not defined" when I run this code:

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

我使用Revit蟒蛇外壳(IronPython的)

I'm using revit python shell (IronPython)

推荐答案

您应导入对象类型到当前范围:

>>> from Autodesk.Revit.UI.Selection import ObjectType
>>> picked = uidoc.Selection.PickObject(ObjectType.Element)

我刚才在RevitPythonShell尝试了这一点,已经注意到了,这是不行的,因为外壳仍然在前台。因此,这种技术会为您添加到功能区的脚本工作,但不是直接从壳......我不太清楚怎么还没有解决这个问题。对不起。

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.

编辑::使用的函数像这样做的伎俩:

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

您可以通过将其粘贴到编辑器窗格底部和按F5或将其添加到您的初始化脚本或其他运行此。然后就叫 pickobject()时,你需要选择一个元素。

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.

这篇关于Python中的Revit拾取对象/选择对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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