Tuesday 23 April 2013

Revit API - Skipping Unplaced Rooms

Using Revit API, if you want to collect all "Placed" rooms in a given Revit project file and want to skip all "Unplaced" rooms then use the following method.

Get "All" rooms in a project file using standard filter collector method and iterate through each room object to check the following before you add them to your final "Placed Rooms" collection.


// find the rooms, skip those rooms which are not placed but exist in a project file. Checking if Area property of room is 0.0 and location property is null.

                Room tmpRoom = obj as Room;
                if (null != tmpRoom.Location  && Math.Round(tmpRoom.Area) != 0.0)
                {
                    m_rooms.Add(tmpRoom);
                    continue;
                }


The reason why I list this method here is because I used the following up until now and it worked well but for some reason it stopped working in Revit 2013 API while I was updating my plugins. When I checked using Revit snoop database..all unplaced rooms show Level property that they were last placed and deleted and show null property in object type.


// find the rooms, skip those rooms which don't locate at Level yet.

                Room tmpRoom = obj as Room;
                if (null != tmpRoom && null != tmpRoom.Level)
                {
                    m_rooms.Add(tmpRoom);
                    continue;
                }


2 comments:

  1. I have updated my code to check for the room area. But now I am receiving an Object reference error. Did you encounter this originally? Do you have a solution? Thanks.

    ReplyDelete
  2. No I didn't encounter this error. Try debugging your code step by step and see what throws this error.

    ReplyDelete