AI, Boundaries, Loops and RevitApiDocs 2020

Yet another eagerly awaited update for the Revit 2020 API, a couple of interesting Revit API discussion forum threads, and some thoughts on how AI might affect and be used in an architectural context:

RevitApiDocs Updated with the Revit 2020 API

@RevitApiDocs announced the update of for the Revit 2020 API:

This update also includes:

Thanks to @60secondrevit for sending the .chm file and @yarnchitect for nudging me and testing beta release.

RevitApiDocs 2020

Many thanks to Gui Talarico for this eagerly awaited update!

More Room Boundary Segments than Expected

Two separate questions were raised in the Revit API discussion forum asking why a rectangular room might return more than the expected four boundary segments:

The first thread provides an answer for both:

Question: A question concerning segments that bound a space: In theory, for just a single rectangular room, I should have 4 segments per room; however, in most cases, I get more. I guess this happens because there are some other elements which divide those segments (like a wall).

Room boundary segments

For example, for the case above, I expected 4 segments, but I'm getting 6 instead due the perpendicular wall that divides the segment.

My question is: is there any way to get only the 4 segments?

I'm trying to get the four corners of a room.

Answer: Your assumption is correct.

The separate segments stem from different elements.

Note that you can query each boundary segment for the element that is producing it using its ElementId property.

Retrieve the id of the element that produces this boundary segment. If the segment is created from an element in a link, this is the id of the RevitLinkInstance.

To obtain just four segments for your square room, you can perform some geometric analysis to combine collinear segments into longer pieces.

If all you need are the four corners, you can (much more) easily determine those by stepping through all the segments (optionally tessellated, if they may be curved) and determine their max and min X, Y and Z coordinates.

The solution is similar to the approach below showing how to get width and height of a CurveLoop.

How to get Width and Height of a CurveLoop

I answered a question a couple of weeks ago in the Revit API discussion forum thread asking how to get width and height of Curveloop.

Since the same approach can easily be adapted to obtain the four corners of a room, I'll mention it here also:

Question: How to calculate the height and width of a curve loop as shown below?

Width and height of CurveLoop

Answer: One easy way to get a pretty good approximate value would be to iterate over the curve loop curves, tessellate each curve and determine the minimum and maximum resulting vertex coordinates:

I added something similar to The Building Coder samples for future reference.

To make it more generic, I implemented an extension method ExpandToContain( IEnumerable<XYZ> ) on the bounding box and use it to calculate the bounding box of a curve loop like this:

  /// <summary>
  /// Expand the given bounding box to include 
  /// and contain the given points.
  /// </summary>
  public static void ExpandToContain(
    this BoundingBoxXYZ bb,
    IEnumerable<XYZ> pts )
    bb.ExpandToContain( new XYZ(
      pts.Min<XYZdouble>( p => p.X ),
      pts.Min<XYZdouble>( p => p.Y ),
      pts.Min<XYZdouble>( p => p.Z ) ) );

    bb.ExpandToContain( new XYZ(
      pts.Max<XYZdouble>( p => p.X ),
      pts.Max<XYZdouble>( p => p.Y ),
      pts.Max<XYZdouble>( p => p.Z ) ) );

  /// <summary>
  /// Return the bounding box of a curve loop.
  /// </summary>
  public static BoundingBoxXYZ GetBoundingBox(
    CurveLoop curveLoop )
    List<XYZ> pts = new List<XYZ>();
    foreachCurve c in curveLoop )
      pts.AddRange( c.Tessellate() );

    BoundingBoxXYZ bb = new BoundingBoxXYZ();
    bb.ExpandToContain( pts );
    return bb;

Can you confirm that this works for you as well?

Here are the entire diffs (unfortunately including lots of superfluous whitespace modifications):

Response: I tried your code in my project. It is working without any error and returns expected result. Thank you.

AI and Architecture

Let's end by mentioning this interesting overview of AI and Architecture from an experimental perspective by Stanislas Chaillou of Harvard Graduate School of Design.

Here are a few abbreviated quotes from his conclusion:

AI and Architecture