ISelectionFilter inside python node

Hi,
Tried to implement code as mentioned at dynamopythonprimer book, but faced with a following issue. Do somebody know what’s wrong?

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

@denisyukj ,

at first look “Walls” seems to be wrong you need “OST_Walls”

KR

Andreas

Hello, look at this message you have the why

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

cordially
christian.stan

2 Likes

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

1 Like

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

1 Like

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

Cordially
christian.stan

There are some explanations about this issue
here

and here

this should be fixed in the next version of PythonNet (3.1.0) :crossed_fingers:

3 Likes

Is it fixed now?

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.

2 Likes