Hello my name is Daniel.
I am working on custom element parameter/property exporter addin.
And I have come across, what seems to be a bug in the API.
It has to do with room reference properties for FamilyInstances of Doors and Windows.
The normal behavior of the API is;
I can get a Room element by accessing Door's Room/RoomFrom/RoomTo properties.
This works fine when Phases in current model file are in their default state:
1 Existing
2 New Construction
At this point any doors or rooms added to the model will automatically be on New Construction.
But as soon as the new Phase is added via User Interface, that is after New Construction,
the Room/RoomFrom/RoomTo references in Door's FamilyInstance properties are all NULL.
This behavior can be tested with RevitLookup that is part of every Revit API release.
I was wondering if anyone has come across this issue before, is this a bug?
This issue can be resolved by combining all phases after the New Construction phase.
Basically resetting the Phases back to default state.
The naming of Phases has no effect. The only condition is; no phases can exist after New Construction (or Phase that contains rooms).
Revit schedules still work fine, the Room reference is there, but via API it’s NULL
Hope the question is clear.
Thank you.
Great Catch Daniel!
I have my own door renumber addin and never noticed this before.
Although I do not have a great solution I did try a couple thing that you may have already tried, but wanted to mention.
By moving the rooms to the most recent phase (most future if you prefer) the Room/RoomFrom/RoomTo properties return valid data.
To rephrase, the Room/RoomFrom/RoomTo properties only work if the rooms are in the newest phase.
Again, this may not be a valid solution for your issue.
Take care!
If you want a specific phase-room relations, use the methods:
public Room get_FromRoom(Phase phase);
public Room get_Room(Phase phase);
public Room get_ToRoom(Phase phase);
I dug up this discussion because I have just been confronted with the same problem and I think I have an explanation.
Rooms are not working the same as other elements when it comes to phases. Rooms does not have a created and a demolished phase. They are associated to a single phase (you can get it by reading the ROOM_PHASE_ID parameter). This is normal because for a room to be placed, it needs limits. These limits (wall, lines) can be created or demolished in different phases, so the room can not exists in multiples phases.
So ToRoom, Room and FromRoom properties always return the rooms of the last phase of the project. When you work with the standard template, you only have two phases, and the last is the default, so you don't have any problems. But if you add some phases, ToRoom and FromRoom will return null if your rooms are not associated to the last phase. In fact, you need to always use the overloads : get_FromRoom, get_Room and get_ToRoom like @GoncaloFeio1321 says, because there can be multiples values for one door (one door can open in a bedroom, but in another phase, the bedroom can be changed to an office).
In fact, ToRoom, Room and FromRoom should be removed from the API (I know, it will break a lot off addins), because they confuse the developper.