2

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?

user3460882
  • 125
  • 1
  • 7
  • I am afraid I do not know the answer to your question. It looks all right to me. However, your call to ToElements is unnecessary and inefficient. The filtered element collector itself is already iterable. ToElements creates a copy of the entire collection. Here is a detailed discussion of the similar inefficiency of ToElementIds: http://thebuildingcoder.typepad.com/blog/2012/12/toelementids-performance.html – Jeremy Tammik Aug 17 '16 at 18:17
  • please note that the same question is also discussed in the revit api discussion forum thread http://forums.autodesk.com/t5/revit-api/toroom-fromroom-python-issue/m-p/6507328 – Jeremy Tammik Aug 18 '16 at 08:24
  • Jeremy thank you for the hint pertaining the filtered element collector. – user3460882 Aug 18 '16 at 12:35

2 Answers2

3

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 Thomas
  • 67,947
  • 40
  • 154
  • 200
  • thanks, thomas! the developer discovered the same thing and shared his working solution using the same approach you recommend in the Revit API discussion forum http://forums.autodesk.com/t5/revit-api/toroom-fromroom-python-issue/m-p/6507328 – Jeremy Tammik Aug 18 '16 at 14:57
  • And how did you know to do that exactly .. ? I would have never guessed from the Revit API description that this is the correct way to use the FromRoom property. room.get_Parameter(DB.BuiltInParameter.ROOM_NAME).AsString() if you are after the Name as per this [link](https://forums.autodesk.com/t5/revit-api-forum/exception-system-missingmemberexception-name-amp-amp-indexer-has/td-p/8138318) – Dido Nenov Feb 01 '21 at 18:07
0

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))`
user3460882
  • 125
  • 1
  • 7