Curves or lines from room.GetboundarySegments

Hi i’m trying to create area based on the boundaries of rooms from a linked model.

But i’m having trouble converting the room.GetboundariySegments to curves/lines to be able to use them for the are boundray creation.
anybody having any idea?

the problem seems the be that the segments can be in list in list (in list) depending on wheter or not the room has multiple boundarieloops.

# =======================================================================
# IMPORTS
# =======================================================================
import sys
sys.path.append(r'H:\\_GROEPEN\\CAD\\DEV\\Tools\\CMRP')

from pyrevit import script
from pyrevit import UI
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *
from Autodesk.Revit.DB import *

from CMRPGUI import *

# Doc & App
# -----------------------------------------------------------------------
doc = revit.doc
uidoc = revit.uidoc

def areatoroom(doc):
        # lists
        # -----------------------------------------------------------------------
        room_names, room_numbers, room_boundaries, room_Id, room_lvls = [], [], [], [], []
        room_views = []
        linked_lvl_name = []
        
        lvls_ex = FilteredElementCollector(doc).OfClass(Level).ToElements()
        lvls_ex_names = [lvl.Name for lvl in lvls_ex]
        
        options = SpatialElementBoundaryOptions()
        options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish
        
        # Select link document & the linked-rooms
        # -----------------------------------------------------------------------
        links = link_selection(doc)
        for link in links:
                link = link.GetLinkDocument()
                rooms = FilteredElementCollector(link).OfCategory(BuiltInCategory.OST_Rooms).ToElements()
                # Get rooms information from linked model
                # -----------------------------------------------------------------------
                for room in rooms:
                        room_Id.append(room.UniqueId)
                        room_names.append(Element.Name.GetValue(room))
                        room_numbers.append(room.Number)
                        # boundaries information - curves
                        room_segments = []
                        lines = []
                        room_segments.append(room.GetBoundarySegments(Options))
                        for segment in room_segments:
                                for curve in segment:
                                        if isinstance(curve, lines):
                                                lines.append(curve)
                        room_boundaries.append(lines)
                        # lvl information
                        lvl_Id = (room.LevelId)
                        lvl = link.GetElement(lvl_Id)
                        linked_lvl_name.append(lvl.Name)
                # Get corresponding lvls from the analysismodel
                # -----------------------------------------------------------------------
                room_lvls = [lvls_ex[lvls_ex_names.index(name)] for name in linked_lvl_name]
                room_lvl_ref = [lvl.GetPlaneReference for lvl in room_lvls]
                # Get corresponding view of lvl
                # -----------------------------------------------------------------------
                for view in FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views):
                        # Check if the view name starts with "13_"
                        if view.Name.startswith("13_"):
                                level_name = view.Name.replace("13_", "")
                                # Check if the level name is in the list of level names
                                if level_name in lvls_ex_names:
                                        room_views.append(view)
                print(room_views)
                # New boundary lines
                # -----------------------------------------------------------------------
                room_boundaries.NewAreaBoundaryLine(room_lvl_ref, room_boundaries, room_views)

areatoroom(doc)

Solved it :slight_smile:

for those intressed, i needed to go one layer deeper:

for room in rooms:
                        room_Id.append(room.UniqueId)
                        room_names.append(Element.Name.GetValue(room))
                        room_numbers.append(room.Number)
                        # boundaries information - curves
                        room_segments = []
                        lines = []
                        room_segments.append(room.GetBoundarySegments(options))
                        for segment in room_segments:
                                for subsegment in segment:
                                        for curve in subsegment:
                                                lines.append(curve.GetCurve())
                        room_boundaries.append(lines)

yep, for reference, always go to the api documentation, there are examples that do make sense sometimes/often

is there a difference between your link and the revitapi docs website?
NewAreaBoundaryLine Method (revitapidocs.com)

The only difference is the direct access to code samples in c# vb and py using the <> button at the top right of most of the API components.
That is the reason why I prefer the API docs website.

1 Like

thx @Jean-Marc i dind’t notice that button :slight_smile:
handy indeed