Boost Your BIM – making Revit even better

July 22, 2013

Using BoundingBoxContainsPointFilter with Rooms & Filled Regions

Filed under: Rooms — Harry Mattison @ 10:45 am

One of the Revit users who I have been teaching how to use the Revit API had this question:

“I want to renumber my rooms automatically in a floor plan view by getting the room’s location point and seeing if it falls within the boundary of a filled region. I would have a grid of filled regions overlaid on the plan, each with a unique comment, such as ‘A1′, ‘A2′, ‘B1′, etc. The code would write the comments value into the room’s number parameter.

My firm’s standard for room naming is to overlay a grid on top of the plan and number each room based on the coordinates of the grid (plus the level number in front). So a person has to do this manually which takes a while. My idea was to put the info into the filled regions (which when grouped could be reused over and over) and number the rooms automatically based on the room location point.”

We solved this as follows. The BoundingBoxContainsFilter is used to find the filled region that is on top of each room:

public void NumberRoomByRegion()
    Document doc = this.ActiveUIDocument.Document;

    using (Transaction t = new Transaction(doc,"Set Rooms By Region"))
        foreach (Room r in new FilteredElementCollector(doc).OfClass(typeof(SpatialElement)).OfCategory(BuiltInCategory.OST_Rooms).Cast<Room>().Where(q => q.Area > 0))
            XYZ roomPoint = ((LocationPoint)r.Location).Point;
            IList<Element> overlapList = new FilteredElementCollector(doc,doc.ActiveView.Id).OfClass(typeof(FilledRegion)).WherePasses(new BoundingBoxContainsPointFilter(roomPoint)).ToList();
            if (overlapList.Count > 1)
                TaskDialog.Show("Error","Skipping room " + r.Name + ". Overlaps with more than one filled region.");
            else if (overlapList.Count == 0)
                Element e = overlapList.First();
                r.Number = e.get_Parameter("Comments").AsString();
About these ads

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

The WordPress Classic Theme Blog at


Get every new post delivered to your Inbox.

Join 972 other followers