带有 ISelectionFilter 的 PickObjects 不允许我 select 任何东西,为什么?

PickObjects with ISelectionFilter will not allow me to select anything, why?

我正在尝试通过使用 GUI 启用 selecting 一个 space 以便在 Revit MEP 2019 中使用,并存储 selection 以便在脚本中进一步使用。代码是用 pyRevit 编写的。该脚本从 shell 和插件按钮运行,但是当进入 selection 模式(PickObject 方法)时,我根本不允许 select 任何东西。我没有收到任何错误,只是在 GUI 中输入 selection 工具时没有任何内容 select。

我在代码中评论了我尝试过但没有用的东西。

from Autodesk.Revit              import DB,UI
from Autodesk.Revit.DB           import BuiltInCategory
from Autodesk.Revit.UI.Selection import ISelectionFilter,ObjectType

# Definitions:

# Define a space selection filter so that only spaces are selectable
class SpaceSelectionFilter(ISelectionFilter):
    def AllowElement(element):
        #if element.Category.Name == "Spaces":
        #if element.ToString() == "Autodesk.Revit.DB.Mechanical.Space":
        if element.Category.Id.IntegerValue== int(BuiltInCategory.OST_MEPSpaces):
            return True
        return False

    def AllowReference(reference, point):
        return False

# Function that enables using PickObject from the PythonRevitShell
def shell_pickobject():
    __window__.Hide() 
    elementReference = uidoc.Selection.PickObject(UI.Selection.ObjectType.Element,spaceFilter,"Select a space(room)") 
    __window__.Show()
    __window__.TopMost = True
    return elementReference

# Procedure:    

# Create a selection filter
spaceFilter = SpaceSelectionFilter()

# User picks a space    
ref =  shell_pickobject()

# The following line works also outside of the shell_pickobject() function when used from the GUI addin-button, but spaces are still not selectable.
# elementReference = uidoc.Selection.PickObject(UI.Selection.ObjectType.Element,spaceFilter,"Select a space(room)") 

我不明白问题出在哪里,我最好的猜测是在过滤器定义内。帮助字符串 "Select a space(room)" 正确显示在左下角,当我应该 select 视图中的某些内容时,除了视口之外的所有内容都变成灰色。鼠标变成某种 "forbidden" 符号。

非常感谢您对此提供的帮助。预先感谢任何可能希望提供帮助的人!

您可以在 pyRevitMEP source code. I also did an article explaining how to use ISelectionFilter : [Revit] ISelectionFilter example using python 中找到示例。这是一个例子(运行 revitpythonshell):

from Autodesk.Revit.UI.Selection import ISelectionFilter

class CustomISelectionFilter(ISelectionFilter):
    def __init__(self, category_name):
        self.category_name = category_name
    def AllowElement(self, e):
        if e.Category.Name == self.category_name:
            return True
        else:
            return False
    def AllowReference(self, ref, point):
        return true

try:
    ductsel = uidoc.Selection.PickObject(ObjectType.Element,
    CustomISelectionFilter("Ducts"),
    "Select a Duct")            
except Exceptions.OperationCanceledException:
    TaskDialog.Show("Operation canceled","Canceled by the user")

__window__.Close()

您可以在此处解释的 pyRevit 下找到另一个示例 运行:[pyRevitMEP] ConnectTo : connect MEP elements