Select Model Elements By Category keeps changing the category on its own

It’s in Revit 2024 / Dynamo 2.19

I save a graph, where the node is set to Selecting the Rooms category:

Once someone tries to run it, it does not Select rooms and when I revise it turns out the category had somehow switched to something else - more often than not - to Ramp Arrow :smiley:

I thought this might happen when someone tries to run it in a project where not a single room is present, but this is not the case.

I’ll just write my own node to do that, but I was wondering what might be the issue

that’s my solution to the problem, at least for now


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 RoomSelectionFilter(ISelectionFilter):
    def __init__(self):
        pass
        
    def AllowElement(self, element):
        try:
            if element.Category is not None and element.Category.Id.IntegerValue == int(BuiltInCategory.OST_Rooms):
                return True
            return False
        except:
            return False
        
    def AllowReference(self, reference, position):
        return False

try:
    room_filter = RoomSelectionFilter()
    message = "Select room(s). Press ESC to cancel."
    selected_refs = uidoc.Selection.PickObjects(ObjectType.Element, room_filter, message)
    selected_elements = [doc.GetElement(ref) for ref in selected_refs]
    room_elements = [elem.ToDSType(True) for elem in selected_elements]
    OUT = room_elements

except Exception as e:
    if "Canceled" in str(e) or "cancelled" in str(e).lower():
        OUT = "Selection canceled by user."
    else:
        OUT = str(e)
1 Like

Is there any chance someone is opening this in another version of Revit, or that a cloud service is mucking about in between you setting the dropdown and the user having it modified?

This might also be a silly little thing but if you run it through dynamo and you hover over the category and accidently scroll it will change the category too.

1 Like

it is technically possible, but not within this timeframe

sounds funny, but I tried it and could not recreate it :slight_smile: