Collect all entries for a BuiltInParameter

Hi there!

I am trying to wrap my head around how to collect all the Departments in a project. I’ve read through many examples ( https://thebuildingcoder.typepad.com/blog/2010/06/parameter-filter.html, https://danimosite.wordpress.com/2017/04/16/filteredelementcollector-and-how-to-use-it-in-python-for-dynamo/, https://digitteck.com/dotnet/revitapidotnet/revitapi-getting-parameters/ ), but they all rely on some filter to cull results, or at the last link they get just one Department from one room element. I know the builtinparameter enumeration is ROOM_DEPARTMENT, I would like to collect all of them. I’m sure it’s simple and I just haven’t seen it done yet… right? :weary:

Something like this?

from pyrevit import DB, revit

doc = revit.doc

RoomDepartmentCollector_count=0

RoomDepartmentCollector= DB.FilteredElementCollector( doc ).OfCategory(DB.BuiltInCategory.OST_Rooms).ToElements()

RoomDepartmentCollector_count= str(len(RoomDepartmentCollector))

rooms_names_and_departments =[]

for i in RoomDepartmentCollector:
    rooms_data = []
    rooms_data.append(i.get_Parameter(DB.BuiltInParameter.ROOM_NAME).AsString())
    rooms_data.append(i.get_Parameter(DB.BuiltInParameter.ROOM_DEPARTMENT).AsString())
    rooms_names_and_departments.append(rooms_data)

print (rooms_names_and_departments)
print(RoomDepartmentCollector_count)

loads of documentation around that topic:

I would do something like this to collect all values of room departments (untested).

all_rooms = DB.FilteredElementCollector(doc)\
    .OfCategory(DB.BuiltInCategory.OST_Rooms)\
    .WhereElementIsNotElementType()

all_departmenets = set()

for room in all_rooms:
    all_departmenets.add(room.get_Parameter(DB.BuiltInParameter.ROOM_DEPARTMENT).AsString())

Ahh so there is no direct way to collect the Departments, I would have to loop through all the rooms to get them, and using a set() makes it so duplicates are eliminated. Nice solution, too bad there isn’t a more efficient way (ie skipping the room collection step).

Also, if a Department was created earlier, but then deleted from all rooms, this method misses collecting that Department value. Maybe there is another way???

Thanks for the help so far - any other ideas?

You are correct that this would only gather in-use departments. For the deleted departments, can you access that information from anywhere inside the standard user interface?
As far as I can tell it’s just a text parameter, so if the information goes away it’s not in ‘some master list’ elsewhere.
(An example of this master list is the Space Type parameter)

They’re available in a “master list” of sorts in the Edit Color Scheme dialogue.

I believe they just added support for color schemes to the API in revit 2022. DB.ColorFillScheme.GetEntries() --> ColorFillSchemeEntry.GetStringValue()
I haven’t really played around with this yet, though.