ISelectionFilter in Revit 2023

Hi All,

I’ve been getting a weird error where the selection filters aren’t being implemented for the pickobjects method. Can anyone advise / replicate / confirm? CPython3

Node Name: Python Script
Package: Core.Scripting
Dynamo Version: 2.16.1.2727
Host: Dynamo Revit
Messages: TypeError : object does not implement ISelectionFilter [’ File “”, line 34, in \n’]
State: Warning

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

class Single_Category(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


msg = 'Select Multiple Gridlines.\n\nPress Finish to complete.'
TaskDialog.Show("User Input Required", msg)

selection = uidoc.Selection
category_filter = Single_Category("Grids")
elements = selection.PickObjects(ObjectType.Element, category_filter)

if elements:
    gridlines = [doc.GetElement(x.ElementId) for x in elements]
else:
    gridlines = []

OUT = gridlines

These types of filters work fine in 2021 and 2022.

Could have something to do with this, namespace and object issues?

Node Name: Python Script
Package: Core.Scripting
Dynamo Version: 2.16.1.2727
Host: Dynamo Revit
Messages: AttributeError : type object ‘Selection’ has no attribute ‘ISelectionFilter’ [’ File “”, line 17, in \n’]
State: Warning

Hello, same message as you, for your information
For the resolution, I am not yet alert enough on these aspects.

Cordially
christian.stan

1 Like

Mr. Poupin’s code and yours are similar
on the class of the Filter (I may not be using the right term)
Passing filter is not done (Must have some relation with CPython3)

Capture d’écran 2023-03-15 151548
image

cordially
christian.stan

2 Likes

Hi,

it’s a current PythonNet issue

see here.

3 Likes

Thanks all :slightly_smiling_face:

Bugger, that’s a shame it’s on the wait list. :disappointed_relieved:

I guess I’ll just use the pickobjects method without the selection filter and just filter the elements of the required category after.

2 Likes

We have on the backlog work to update these components and some of them have been fixed on the PythonNET side :slight_smile: Sadly no ETA as we can’t give that out, but we’re aware, and it’s in queue!

8 Likes

hello, I tried isolating category then selection, I don’t know how to return to the initial state but you must know (I’ve found)

if interested I leave you script (edit script too)

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

view_current=doc.ActiveView
a=UnwrapElement(IN[0])
b=a.Id

TransactionManager.Instance.EnsureInTransaction(doc)

view_current.IsolateCategoryTemporary(b)

msg = 'Select Multiple Gridlines.\n\nPress Finish to complete.'
TaskDialog.Show("User Input Required", msg)

selection = uidoc.Selection
elements = selection.PickObjects(ObjectType.Element)
exit=[doc.GetElement(x.ElementId) for x in elements]
view_current.TemporaryViewModes.DeactivateAllModes()

TransactionManager.Instance.TransactionTaskDone()

OUT = exit

Cordially
christian.stan

3 Likes