Collecting Rooms from Main Model and Primary Design Options

Hi everyone,
I’m trying to use a filtered element collector to get all the rooms in the project, without the secondary design options. I want just Main model and primary design option rooms. I’ve made use of the PrimaryDesignOptionMemberFilter which only grabs the rooms in the primary options. Now I just need the main model rooms, and I’m trying to use an if statement to check if the i.designoption equals null, but it’s not working. Anyone have ideas or an easier way?

clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import Revit Nodes 
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

# Import DocumentManager and TransactionManager
clr.AddReference ("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

filter = PrimaryDesignOptionMemberFilter()
coll1 = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).ToElements()
coll2 = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WherePasses(filter).ToElements()
#coll3 = coll1.UnionWith(coll2)

roomname = []
roomlevel = []
roomnum = []
area = []
department = []

TransactionManager.Instance.EnsureInTransaction(doc)

for i in coll1:
	options = SpatialElementBoundaryOptions()
	if i.Area != 0.00 and i.Location != "null" and len(i.GetBoundarySegments(options)) != 0 and i.DesignOption == "null":
		roomname.append(i.LookupParameter("Name").AsString())
		department.append(i.LookupParameter("Department").AsString())
		area.append(i.LookupParameter("Area").AsValueString())
		roomlevel.append(i.LookupParameter("Level").AsValueString())

The Python equivalent of a null is a NoneType object, or simply None. Therefore, your test should look like this:

i.Location is not None

You can also simplify your code using the all() function like this:

if all((
    i.Area != 0, 
    i.Location is not None, 
    len(i.GetBoundarySegments(options)) != 0, 
    i.DesignOption is not None
)):
2 Likes

Thank you. I knew it had to be something simple.

Follow up related question: Within that same if statement, how do check to see if an element is in the primary option?

The DesignOption class has an IsPrimary property, so you can do it like this:

# Assume 'element' is a valid Revit Element
if element.DesignOption.IsPrimary:
    # Do stuff