# ISelectionFilter inside python node

**URL:** <https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367>\
**Category:** Developers\
**Tags:** python\
**Created:** [July 31, 2023, 1:34pm UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367 "2023-07-31T13:34:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![denisyukj](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/denisyukj/32/166182_2.png) [@denisyukj](https://forum.dynamobim.com/u/denisyukj)\
**Post date:** [July 31, 2023, 1:34pm UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367/1 "2023-07-31T13:34:39Z")

</div>

Hi,  
Tried to implement code as mentioned at [dynamopythonprimer](https://dynamopythonprimer.gitbook.io/dynamo-python-primer/4-revit-specific-topics/prompting-ui-selection) book, but faced with a following issue. Do somebody know what’s wrong?

```auto
import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import ISelectionFilter

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

class MySelectionFilter(ISelectionFilter):
	def __init__ (self):
		pass
	def AllowElement(self, element):
		if element.Category.Name == "Walls":
			return True
		else:
			return False
	def AllowReference(self, element):
		return False

selection_filter = MySelectionFilter()

walls = uidoc.Selection.PickElementsByRectangle(selection_filter)
OUT = walls

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/b/2b69ffa69dbc6b5774a2bcf118356a5ae205675a.png)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [July 31, 2023, 2:08pm UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367/2 "2023-07-31T14:08:38Z")

</div>

@denisyukj ,

at first look “Walls” seems to be wrong you need “OST\_Walls”

KR

Andreas

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [July 31, 2023, 2:13pm UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367/3 "2023-07-31T14:13:00Z")

</div>

Hello, look at this message you have the why

> [@ISelectionFilter in Revit 2023](https://forum.dynamobim.com/t/iselectionfilter-in-revit-2023/87372):
>
> 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') f…

edit:  
you have this library node (written in C# I think)  
for landing

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/b/bb5f8239fdefed62072542d174ce1e90d3db3686.png)

cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [July 31, 2023, 2:40pm UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367/4 "2023-07-31T14:40:27Z")

</div>

For a ‘one time use’ make sure that your class has a namespace assigned.

---

<div class="post-metadata">

**Author:** ![denisyukj](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/denisyukj/32/166182_2.png) [@denisyukj](https://forum.dynamobim.com/u/denisyukj)\
**Post date:** [July 31, 2023, 3:25pm UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367/5 "2023-07-31T15:25:38Z")

</div>

@christian.stan  
Thank you. I know about this selection nodes, just trying to dive into programing 🙂  
So right now it’s a PythonNET issue, am I correct?

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [July 31, 2023, 3:39pm UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367/6 "2023-07-31T15:39:33Z")

</div>

yes as pointed out by Mr. Poupin and in Mr. Solamour’s bag which must be heavy  
from what I understood

Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [July 31, 2023, 3:43pm UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367/7 "2023-07-31T15:43:56Z")

</div>

There are some explanations about this issue  
here

> <https://github.com/pythonnet/pythonnet/pull/2055>
>
> \### What does this implement/fix? Explain your changes.
> 
> This PR addresses the…se issues:
> \- Current pythonnet does not allow subclassing from CLR Abstract classes
> \- Running python script with types containing \`\_\_namespace\_\_\`, more than once, would throw \`Type Exists\` exception
> \- Calling \`super().VirtualMethod()\` inside a python-derived virtual method, would result in an infinite loop
> 
> Due to the nature of the changes, this is a single PR instead of multiple smaller ones.
> 
> After PR merge:
> \- Python types can derive from CLR abstract classes. As before, abstract methods that are not implemented on the python type, will dynamically throw \`NotImplemented\` exception.
> \- Specifying \`\_\_namespace\_\_\` is not required to created a \`ClassDerived\` anymore. All python derived classes are now represented by \`ClassDerived\` in managed memory.
> \- \`ClassDerived\` now caches generated types based on namespace, type name, and chain of base classes. This avoids regenerating types or throwing \`Type Already Exists\` exceptions. A new format for generated type names include full name of base class and interfaces in the typename. The naming format still ends in the python type name to be backward compatible and passes the unit tests
> - \*\*Example:\*\* Full name of derived clr type for python type named \`SubClass\`, deriving from \`BaseClass\` and implementing \`BaseInterface1\` and \`BaseInterface2\`:
> \`Python.Runtime.Dynamic.BaseClass\_\_BaseInterface1\_\_BaseInterface2\_\_main\_\_SubClass\`
> \- Support for one base class and multiple interfaces (Merged some ideas and code from #2028 - Potential merge conflicts)
> \- Derived class can call chosen constructors using \`super().\_\_init\_\_()\` pattern.
> 
> \`\`\`python
> class SubClass(BaseClassA):
> def \_\_init\_\_(self, v):
> super().\_\_init\_\_(v)
> \`\`\`
> \- Derived class can call base virtual methods using \`super().method()\` pattern.
> \`\`\`python
> class SubClass(BaseClassA):
> def DoWorkWith(self, value):
> r = super().DoWorkWith(value) + 10
> return r
> \`\`\`
> \- Improved virtual method and getter/setter routing. Custom attributes (\`OriginalMethod\` and \`RedirectedMethod\`) are now used to mark the original and redirected virtual methods. The method name format for \`OriginalMethod \` is changed to \`$"\_BASEVIRTUAL\_\_{name}"\` so it can handle calling original methods on base classes that does not match the name of current class. Previously this was not working.
> \- Other misc refactoring and improvements. No change in behavior. 
> 
> \### Does this close any currently open issues?
> 
> Potentially (no tests have been done to ensure these issues are resolved)
> \- #1945
> \- #1107
> \- #1787
> 
> \### Any other comments?
> 
> ...
> 
> \### Checklist
> 
> Check all those that are applicable and complete.
> 
> \- \[X\] Make sure to include one or more tests for your change
> \- \[X\] If an enhancement PR, please create docs and at best an example
> \- \[X\] Ensure you have signed the \[.NET Foundation CLA\](https://cla.dotnetfoundation.org/pythonnet/pythonnet)
> \- \[X\] Add yourself to \[\`AUTHORS\`\](../blob/master/AUTHORS.md)
> \- \[X\] Updated the \[\`CHANGELOG\`\](../blob/master/CHANGELOG.md)

and here

> <https://github.com/pythonnet/pythonnet/pull/2028>
>
> Added support for multiple inheritance when inheriting from one base class and/o…r multiple interfaces.
> 
> Added a unit test verifying that it works with a simple class and interface. This unit test would previously have failed since multiple types are in the class super class list.
> 
> Close #1783
> 
> \### Checklist
> 
> Check all those that are applicable and complete.
> 
> \- \[X\] Make sure to include one or more tests for your change
> \- \[X\] If an enhancement PR, please create docs and at best an example
> \- \[X\] Ensure you have signed the \[.NET Foundation CLA\](https://cla.dotnetfoundation.org/pythonnet/pythonnet)
> \- \[X\] Add yourself to \[\`AUTHORS\`\](../blob/master/AUTHORS.md)
> \- \[X\] Updated the \[\`CHANGELOG\`\](../blob/master/CHANGELOG.md)

_this should be fixed in the next version of PythonNet (3.1.0)_ 🤞

---

<div class="post-metadata">

**Author:** ![christopher-estrada](https://avatars.discourse-cdn.com/v4/letter/c/c77e96/32.png) [@christopher-estrada](https://forum.dynamobim.com/u/christopher-estrada)\
**Post date:** [December 7, 2023, 7:26am UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367/8 "2023-12-07T07:26:06Z")

</div>

Is it fixed now?

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [December 11, 2023, 9:15am UTC](https://forum.dynamobim.com/t/iselectionfilter-inside-python-node/92367/9 "2023-12-11T09:15:22Z")

</div>

Unfortunately not, the arrival of Net 7-8 will complicate things with PythonNet 2.5.2. I currently recommend Ironpython2 (or better still IronPython3), or else to make a c# library.
