revitapi ironpython ToRoom returns “indexer # object”

一曲冷凌霜 提交于 2019-12-10 22:46:20

问题


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?


回答1:


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...




回答2:


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))`


来源:https://stackoverflow.com/questions/39001482/revitapi-ironpython-toroom-returns-indexer-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!