Riffing on @c.poupin’s code, here’s a recursive function that will scrape every room it can find.
from pathlib import Path
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
def get_rooms(doc):
yield from FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)
def get_all_rooms(doc, rooms=dict()):
path = Path(doc.PathName)
if path.stem not in rooms:
rooms.setdefault(path.stem, []).append(get_rooms(doc))
# Explore links
links = FilteredElementCollector(doc).OfClass(RevitLinkInstance)
for link in links:
link_doc = link.GetLinkDocument()
if link_doc:
rooms = get_all_rooms(link_doc, rooms)
return rooms
doc = DocumentManager.Instance.CurrentDBDocument
OUT = get_all_rooms(doc)
Edit: The above code will only scrape the first instance of a document
Interestingly, multiple instances of the same nested file with rooms returns identical rooms
