Searchable items box

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!! :fire: :fire: :robot: :robot: