Hi, Apologies if this has been covered before. I been upgrading OkPy tools that I have developed and the search box doesn’t seem to work. This is in Rvt25 Orkestra 1.9.10.0 , whilst on this subject there seem to be many hurdles to cross to get Selection Filters working if at all.
hey there!
Indeed the search is borken unfortunately in net8 revit (2025+). We’ve fixed it for 2.0 which is to be release very soon .
can you please elaborate on this part ? :
Thank you for the reply and looking forward to 2.0 release. To clarify I’m referring to the ISelectionFilters and other filters where the OkPy namespace for filters is added. When I first run nothing can be selected so the code is esc, if tried again it reports that there are duplicate assemblies. For now in the tools I’ve had to revert to a method where the user keeps selecting elements until the correct element is selected. As ever any help is much appreciated.
import clr
clr.AddReference(“RevitAPI”)
from Autodesk.Revit.DB import *
clr.AddReference(“RevitAPIUI”)
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import ObjectType, ISelectionFilter
from Autodesk.Revit.DB import ElementId, BuiltInCategory
doc = currentdoc
app = app
uidoc = uidoc
uiapp = uiapp
class MEPSpacesSelectionFilter(ISelectionFilter):
namespace = “OkPyFilters” # Required for PythonNet 3
def AllowElement(self, element):
if element.Category is not None:
return element.Category.Id.IntegerValue == int(BuiltInCategory.OST_MEPSpaces)
return False
# Changed 'moving' to 'position' here
def AllowReference(self, reference, position):
return False
filter = MEPSpacesSelectionFilter()
try:
sel = uidoc.Selection.PickObject(ObjectType.Element, filter, “Select MEP Spaces”)
sel_mepspace = doc.GetElement(sel.ElementId)
except Exception as e:
print("Error: " + str(e))
Aaah right! the ISelectionFilter interface implementation
This is a well-known pythonnet3 headache with ISelectionFilter ,you’ve actually diagnosed it correctly with the namespace attribute, but the issue is that the same namespace string across multiple script runs causes the duplicate assembly conflict. The first-run failure (nothing selectable) is a separate but related issue where pythonnet hasn’t yet registered the dynamic assembly properly before the picker is invoked.
The cleanest fix is to make the namespace unique per run using a guid, which prevents the duplicate assembly error entirely:
import uuid
class MEPSpacesSelectionFilter(ISelectionFilter):
namespace = "OkPyFilters_MEPSpaces_" + uuid.uuid4().hex
def AllowElement(self, element):
if element.Category is not None:
return element.Category.Id.IntegerValue == int(BuiltInCategory.OST_MEPSpaces)
return False
def AllowReference(self, reference, position):
return False
This resolves both the duplicate assembly error on subsequent runs AND the first-run esc issue, since the dynamic assembly is freshly registered each time.
Alternatively, if you want to avoid the uuid overhead and keep a stable namespace, you can guard the class definition so it only gets compiled once per session:
if "MEPSpacesSelectionFilter" not in dir():
class MEPSpacesSelectionFilter(ISelectionFilter):
namespace = "OkPyFilters_MEPSpaces"
though in practice the uuid approach is more reliable across tools and avoids any stale state between revit sessions.
Hope that unblocks you, and thanks for the patience waiting on 2.0! I can tell you it reallon won’t be long before you can try it out, and it contains some minfblowing new toys in OkPy!!
![]()
