Get Room boundaries as Lines

Hello,

I get Code, to get Curves from my Room → RoomBounderies
But it does not work: I use Revit 2023, CPython3

#This script was composed by Roberto Molinos - www.modelical.com

import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

# Import ToDSType(bool) extension method, not sure we need this
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Make sure the GeometryConversion utilities are accesible see https://github.com/DynamoDS/Dynamo/issues/1946
clr.ImportExtensions(Revit.GeometryConversion) 

# Unwrap
rooms = []
for i in IN[0]:
	rooms.append(UnwrapElement(i)) #This kind of opens the Revit element so it can be used by Dynamo Script
# Curve array
curves = []
# Boundary options for rooms
opt = SpatialElementBoundaryOptions()
# Iterate through every room
for room in rooms:
	if room.Area > 0: # Make sure it has positive Area, i.e is placed
		rvBoundary = room.GetBoundarySegments(opt) # Get room boundary
		dsBoundary = [] # A Dynamo list to hold the boundary per room, remember it can be complex, with holes		
		for rvLoop in rvBoundary: # For each loop in the room boundary
			dsLoop = [] # A list to hold each room's loop
			for rvPiece in rvLoop:	# Retrieve each segment of the loop
				dsPiece = Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(rvPiece.Curve,True) # Read the segment as Curve and convert to Dynamo geometry
				dsLoop.append(dsPiece) # Add the piece to the Dynamo Loop
			dsBoundary.Add(dsLoop) # Add the Dynamo Loop to the Dynamo Boundary
		curves.append(dsBoundary) # Add the Dynamo Boundary per room to the Curves list
#Output
OUT = curves

I get an error :frowning: is there a other way to get my room bounderies

currently i get it, but not in detail


KR

Andreas
2022-05-17_14h24_29

The error says the object has no attribute Curve. The correct method is GetCurve.

1 Like
dsPiece = Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(rvPiece.GetCurve,True)

so the error remains, i have to more to access correct method @Nick_Boyts ?

can i learn from that:

public void GetInfo_BoundarySegment(Room room)
{
   IList<IList<Autodesk.Revit.DB.BoundarySegment>> segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

   if (null != segments)  //the room may not be bound
   {
      string message = "BoundarySegment";
      foreach (IList<Autodesk.Revit.DB.BoundarySegment> segmentList in segments)
      {
         foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList)
         {

            // Get curve start point
            message += "\nCurve start point: (" + boundarySegment.GetCurve().GetEndPoint(0).X + ","
                           + boundarySegment.GetCurve().GetEndPoint(0).Y + "," +
                          boundarySegment.GetCurve().GetEndPoint(0).Z + ")";
            // Get curve end point
            message += ";\nCurve end point: (" + boundarySegment.GetCurve().GetEndPoint(1).X + ","
                 + boundarySegment.GetCurve().GetEndPoint(1).Y + "," +
                 boundarySegment.GetCurve().GetEndPoint(1).Z + ")";
            // Get document path name
            message += ";\nDocument path name: " + room.Document.PathName;
            // Get boundary segment element name
            if (boundarySegment.ElementId != ElementId.InvalidElementId)
            {
               message += ";\nElement name: " + room.Document.GetElement(boundarySegment.ElementId).Name;
            }
         }
      }
      TaskDialog.Show("Revit",message);
   }
}

The same error? Or a new one? You do need to match the method exactly which means it should be GetCurve().

Now it’s saying there’s an issue with the ToProtoType method you’re using. Did you include the parenthesis on GetCurve()?

1 Like

there are seviral ways :slight_smile: @Nick_Boyts

dsPiece = Revit.GeometryConversion.RevitToProtoGetCurve().ToProtoType(rvPiece.Curve,True)
dsPiece = Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(rvPiece.GetCurve(),True)

i think it is more than copy paste

The latter is what you want. The GetCurve() method is for getting the underlying curve from the BoundarySegment. The method for conversion is RevitToProtoCurve.

1 Like

@Nick_Boyts

I understand the way it looping thrue my bounderies to get curve.
1.) it filterd the rooms
2.) getting the bounderies
3.) converting it to curves
4.) giving it to the basked

… i got it: there was also add and not append

1 Like

Hi Andreas,
Is it possible to complete the script for getting the bounding box, all 3D lines of the room or the space.
Daniel OLIVES
Lyon-FRANCE

@daniel82KGE ,

i suggest start a new topic