The elements that bound a room

To continue this example, I’ve consolidated 3 lines from the previous post into one line below to get the room object from the user’s selection.

Then I get the BoundarySegment elements that define the room’s boundary. To do this I need to create a SpatialElementBoundaryOptions to specify that I want to get the segments at the finish faces of the bounding elements (the other option would to get the centerline segments).

Room.GetBoundarySegments returns a list of lists which is why the nested foreach loops are needed to get the individual segments. The list of lists makes sense if you think about a room like this, where each loop of segments would be in its own list.


After the individual segments are found, I cast each one from an element to a wall and get its LocationCurve. If this were an element placed in Revit at a point (like a desk) then the location would be a LocationPoint. For elements like Walls and Beams which are curve-driven, the Location is a LocationCurve.

The LocationCurve has a Curve property that returns the geometry of the LocationCurve. This curve is what can be used to find the length of the wall.

            Room room = document.GetElement(uidoc.Selection.PickObject(ObjectType.Element)) as Room;
            SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();
            options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;
            string roomElementInfo = "";
            foreach (IList<Autodesk.Revit.DB.BoundarySegment> boundSegList in room.GetBoundarySegments(options))
                foreach (Autodesk.Revit.DB.BoundarySegment boundSeg in boundSegList)
                     Element e = boundSeg.Element;
                     Wall wall = e as Wall;
                     LocationCurve locationCurve = wall.Location as LocationCurve;
                     Curve curve = locationCurve.Curve;
                     roomElementInfo += e.Name + " " + curve.Length + "\n";
            TaskDialog.Show("Boundary Segment Elements", roomElementInfo);

The screenshot shows the precision of the Revit model and that apparently one of these walls isn’t exactly 10 feet long. If you were presenting this info to the user you might want to use the Math.Round function to clean this up.

5 thoughts on “The elements that bound a room

  1. What an interesting post, a little bit old, but it helped me a lot.
    Is there any way to get the walls information when they are in a linked model?
    I work with spaces in a MEP model with the arch. model linked in…

    thanks in advance!!

  2. Finally I used the architectural room associated to my space and collected all rooms in the arch linked model looking up the matching room. Then, getting it boundary segments works fine!
    In the 99% of times, the mep space will match with a room in the linked model

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s