in revit api i am trying to access the ToRoom / FromRoom properties for doors.
the simplified code snippet in ironpython:
fc = FilteredElementCollector(doc)
doors = fc.OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements()
for door in doors:
froom = door.FromRoom
my result is an "indexer # object at 0x0000000000035"
how can i access the room object from here?
This is an IronPython / funky Revit API issue. Basically, the way FromRoom
is defined, it can be either a property or an indexed property. See the API documentation for FromRoom.
The "indexer" you get is the second version of FromRoom
- it takes a Phase
as its argument. So you can basically do this:
phase = list(doc.Phases)[0]
room = door.FromRoom[phase]
Since the documentation for FromRoom
says it returns
The "From Room" set for the door or window in the last phase of the project.
You probably actually want to do this:
phase = list(doc.Phases)[-1] # retrieve the last phase of the project
room = door.FromRoom[phase]
I was not able to figure out how to get hold of the other version of FromRoom
...
Daren, thank you for your contribution!
after jeremy's answer I examined the same approach.
here is the code snippet
fc = FilteredElementCollector(doc)
doors = fc.OfCategory( BuiltInCategory.OST_Doors ).WhereElementIsNotElementType()
phases = doc.Phases
phase = phases[phases.Size - 1]
for door in doors:
try:
froom = door.FromRoom[phase].Id
except:
froom = -1
try:
troom = door.ToRoom[phase].Id
except:
troom = -1
TaskDialog.Show("Revit","%s, %s" %(froom, troom))`