#RTCNA Wish 3 granted! Join all walls and floors

Here’s how to find all wall/floor intersections and join their geometry. The first, simpler macro prompts the user to select to elements and then joins them. The 2nd one looks at each wall in the model and joins it to all intersecting floors.

BEFORE
before
AFTER
after

public void joinGeometryUserPick()
{
    Document doc = this.ActiveUIDocument.Document;
    UIDocument uidoc = this.ActiveUIDocument;
    
    // prompt user to select two elements
    Element e1 = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element));
    Element e2 = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element));
    
    // join the selected elements
    using (Transaction t = new Transaction(doc, "Join"))
    {
        t.Start();
        JoinGeometryUtils.JoinGeometry(doc, e1, e2);
        t.Commit();
    }
}

public void joinAllWallsFloors()
{
    Document doc = this.ActiveUIDocument.Document;
    using (Transaction t = new Transaction(doc, "Join All Walls/Floors"))
    {
        t.Start();
        foreach (Element wall in new FilteredElementCollector(doc)
             .OfClass(typeof(Wall)))
        {
            // get the bounding box of this wall
            BoundingBoxXYZ bbox = wall.get_BoundingBox(null);
            
            // create an outline from the min and max points of the bounding box
            Outline outline = new Outline(bbox.Min, bbox.Max);
            
            // find all floors that intersect the wall
            foreach (Element floor in new FilteredElementCollector(doc)
                 .OfClass(typeof(Floor))
                 .WherePasses(new BoundingBoxIntersectsFilter(outline)))
            {
                JoinGeometryUtils.JoinGeometry(doc, wall, floor);
            }
                     
        }
        t.Commit();
    }
}
Advertisements

18 thoughts on “#RTCNA Wish 3 granted! Join all walls and floors

  1. Hi
    is it possible to join all walls to walls?
    Because in elevation view sometimes i must join walls to walls to make wall lines invisible.
    Thanks in advance…
    Erdem

    • Change from this:
      foreach (Element floor in new FilteredElementCollector(doc)
      .OfClass(typeof(Floor))
      .WherePasses(new BoundingBoxIntersectsFilter(outline)))
      {
      JoinGeometryUtils.JoinGeometry(doc, wall, floor);
      }

      To this:
      foreach (Element otherWall in new FilteredElementCollector(doc)
      .OfClass(typeof(Wall))
      .WherePasses(new BoundingBoxIntersectsFilter(outline)))
      {
      if (wall.Id == otherWall.Id)
      continue;
      JoinGeometryUtils.JoinGeometry(doc, wall, otherWall);
      }

        • Tried replacing the part… and it gave me an error..

          public void joinAllWalls()
          {
          Document doc = this.ActiveUIDocument.Document;
          using (Transaction t = new Transaction(doc, “Join All Walls”))
          {
          t.Start();
          foreach (Element wall in new FilteredElementCollector(doc)
          .OfClass(typeof(Wall)))
          {
          // get the bounding box of this wall
          BoundingBoxXYZ bbox = wall.get_BoundingBox(null);

          // create an outline from the min and max points of the bounding box
          Outline outline = new Outline(bbox.Min, bbox.Max);

          // find all walls that intersect the other wall
          foreach (Element otherWall in new FilteredElementCollector(doc)
          .OfClass(typeof(Wall))
          .WherePasses(new BoundingBoxIntersectsFilter(outline)))
          {
          if (wall.Id == otherWall.Id)
          continue;
          JoinGeometryUtils.JoinGeometry(doc, wall, otherWall);
          }

          }
          t.Commit();
          }
          }

          • Try also adding this check for AreElementsJoined

            if (wall.Id == otherWall.Id)
            continue;

            if (JoinGeometryUtils.AreElementsJoined(doc, wall, otherWall))
            continue;

            JoinGeometryUtils.JoinGeometry(doc, wall, otherWall);

  2. Hi Harry,

    Could this method enable one to join all of a selection if intersecting / touching?

    Example: select all masonry walls, run macro, walls touching eachother are joined?

    Cheers.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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