Getting rooms with python in Dynamo — Digitteck
Getting rooms with python in Dynamo
dotnet·19 February 2018·1 min read

Getting rooms with python in Dynamo

Description

Getting all rooms in Revit means using the Revit FilteredElementCollector and filtering by the class. The only thing that needs to be remembered is that a Room doesn't directly inherit Element but instead you can use SpatialElement.

In this article the C# approach is translated into Dynamo using Python.

Solution

python
import clr

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitAPI");
from Autodesk.Revit.DB import FilteredElementCollector
from Autodesk.Revit.DB import SpatialElement
from Autodesk.Revit.DB.Architecture import Room

collector = FilteredElementCollector(doc)

collection = collector.OfClass(SpatialElement).ToElements()
rooms = []
for element in collection:
    if (element.GetType().Equals(Room)):
        rooms.append(element)

OUT = rooms

Tags

DynamoPythonRevit.NET
digitteck

© 2026 Digitteck