Maciej Główka
Blog Games Contact

← Return to Blog Index

autoJoin.png
Jan. 30, 2019

Auto-joining floors and walls

revit api

When modelling, Revit automatically joins geometries of intersecting walls – making drafting process a lot faster. It does not happen however for wall and floor pairs. Which results in some extra work while creating sections and can cause errors in schedules. Fortunately it can be easily automated by using Revit API.

At the beginning we have to find all the walls and floors (separately) in the model. We need to skip element type objects.

FilteredElementCollector walls = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType();
FilteredElementCollector floors = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType();

Next, ensuring we work inside a transaction, we are going to check each wall-floor pair whether they overlap. In order to run the script efficiently we are not going to test actual geometry but objects’ bounding boxes.

In order to avoid run-time errors, for each element we check if it produces a valid (non-null) bounding box. Intersection of the boxes is tested by using a simple helper-function, which I am not going to describe in detail. Its code is included however in the final script at the bottom.

foreach(Wall w in walls) {          
  BoundingBoxXYZ wBB = w.get_BoundingBox(null);            
  if(wBB!=null) foreach(Floor f in floors) {      
    BoundingBoxXYZ fBB = f.get_BoundingBox(null);                            
    if(fBB!=null) if(bbIntersect(wBB,fBB)) {    
    }
  }
}

When we find a floor-wall pair that (we suspect) can be joined, we have to check if those elements are not already joined. If not we join them. To avoid crashing the script by a single pair error, we wrap everything in try…catch statement.

if(!JoinGeometryUtils.AreElementsJoined(doc,w,f)) {
  try {              
    JoinGeometryUtils.JoinGeometry(doc, w, f);
  }  
  catch(Autodesk.Revit.Exceptions.ApplicationException)   
  {                  
  }
}

The entire code could look like so:

← Curtain wall dimensions with API and Dynamo Dimensioning elements from linked files with Dynamo→