ISelectionFilter in Python Script not working on RVT2023/CPython3 but working on RVT2021/IronPhyton 2

Hi!
Why this script is not working on CPython3? Any workaround?

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 import *
from Autodesk.Revit.UI.Selection import *

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

Hi,

No work arounds I’m afraid, ISelection doesn’t work in CPython3… All you can do is find another selection method / use another coding language. Hopefully the shift to PythonNet3 will fix them.

Mark

4 Likes

What another coding language do you suggest? Is it possible to do inside Dynamo?

Hey,

I believe the recommended solution is to build a Zero-Touch node using C sharp, it is still possible to install IronPython2.7 but that is not recommended due to security concerns. The Dynamo roadmap has better integration as ‘under consideration’ Roadmap - Dynamo BIM feel free to add to the voices raising this as a priority.

Apologies for not having a better suggestion :frowning:

Mark

1 Like

Ok! Thanks a lot @Mark.Ackerley!

Ironpython3 can be an solution too

1 Like