Maciej Główka
Blog Games Contact

← Return to Blog Index

linkedRoomBoundaries-1.png
May 10, 2019

Room boundaries from linked documents

revit api dynamo

Generating room boundaries with Python is relatively easy. It can be done by using following API call:

loops = room.GetBoundarySegments(options) 

Options is a variable of SpatialElementBoundaryOptions type, which states desired boundary line location, eg. for walls it can be a finish line or centreline. As a result of the above we receive a list of loops, where each loop is a list itself – containing separate segments. In order to get all the single lines we can run a code like this:

for loop in loops:
  for segment in loop:
    c = segment.GetCurve()

Things get complicated though when we try to get boundaries from linked document’s rooms. Linked files can be moved or rotated within our base document and thus running the above code would give us wrong curves locations.

To solve this problem we have to know the transformation (rotation, location) of the linked document. Fortunately Revit API class RevitLinkInstance provides a GetTotalTransform() function that gives us exactly what we need for each instance of the linked doc (same document can be present multiple times within base document – eg. repeated storeys).

Knowing the exact transformation we can correct our curves like so:

transform = linkInstance.GetTotalTransform()
c = segment.GetCurve()
p0 = transform.OfPoint(c.GetEndPoint(0)).ToPoint() p1 = transform.OfPoint(c.GetEndPoint(1)).ToPoint()

Below a complete piece of code which for a specified link instance object will return a list of rooms and their boundary lines:

And a Dynamo definition converting those boundaries into Revit model lines:

linkedRoomBoundaries-1.png
← Resetting MEP systems overrides Finding element location by using Bounding Box in Dynamo→