python和revit_Python中的Revit拾取对象/选择对象

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值