Creating a Crop Box for Room in Elevation View

Hello Dynamo Community,

I’m looking for guidance on how to create a crop box for a room in an elevation view using python script. I’m working on a project where I need to generate elevation views of rooms, and I’d like to automate the process as much as possible.

Specifically, I want to:

  1. Create a crop box around a selected room in an elevation view.
  2. Ensure that the crop box adjusts itself to match the size and position of the room.
  3. Be able to repeat this process for multiple rooms efficiently.

Any advice, tips, or python scripts that can help me achieve this task would be greatly appreciated. Thank you in advance for your assistance!

02 Create Elevation Views for rooms.dyn (97.9 KB)

This one does it. as long as you have a ceiling it will crop the views right.

NOTE. ViewFamily type ahs to be of the kind that exists in elevation Views otherwise it wont work. also set phase. this one creates elevation for the rooms you selects if you want all room in active view it should be easy to modify

I can’t find any node to crop the view.

Actually if you place the elevation correctly, it should crop within the boundaries automatically.
I recommend you place the elevation marker in the corners and then after creating the views of the marker, move the marker to the centre.

Cropping views is an OOTB (out of the box) node, make sure to look for Crop Box (not to be confused with Bounding Box or Section Box)

@c.poupin posted few times solutions for that in the forum also in his blog [Dynamo += Python] Cadrer une Vue 3D (CropBox) ~ VoltaDynaBim


here the case is a little different, it is still necessary to take into account the transformation of the view.
Here I use the solid of the View section and the solid of the part to compute the intersection

adjust section from cropbox from room2

import clr
import sys
import System
from System.Collections.Generic import List
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

import Revit

from System.Reflection import BindingFlags

debug = []
view = UnwrapElement(IN[0])
space = UnwrapElement(IN[1])
margin = IN[2] # in feet
crsm = view.GetCropRegionShapeManager()
cpbbx = view.CropBox
tfBBx = cpbbx.Transform 
pt1 = cpbbx.Min
## compute solid from section View BoundingBox with transform
pt2 = XYZ(cpbbx.Max.X, cpbbx.Min.Y, cpbbx.Min.Z)
pt3 = XYZ(cpbbx.Max.X, cpbbx.Max.Y, cpbbx.Min.Z)
pt4 = XYZ(cpbbx.Min.X, cpbbx.Max.Y, cpbbx.Min.Z)
lstLoopPoints = [pt1, pt2, pt3, pt4, pt1]
lstCurveLoop = List[CurveLoop]()
curveLoop = DB.CurveLoop()
for idx, pt in enumerate(lstLoopPoints):
    if idx > 0:
        curveLoop.Append(DB.Line.CreateBound(lstLoopPoints[idx - 1], pt))

solidSection = DB.GeometryCreationUtilities.CreateExtrusionGeometry(lstCurveLoop, XYZ.BasisZ, cpbbx.Max.Z - cpbbx.Min.Z)
solidSection = DB.SolidUtils.CreateTransformed(solidSection,  tfBBx)
## get solid of Space or Room
calculator = SpatialElementGeometryCalculator(doc)
if calculator.CanCalculateGeometry(space):
    results = calculator.CalculateSpatialElementGeometry(space)
    spaceSolid = results.GetGeometry()
    # compute solid intersection 
    interSolid = BooleanOperationsUtils.ExecuteBooleanOperation(solidSection, spaceSolid, BooleanOperationsType.Intersect)
    # get the parallel face to the view orientation
    face = max((f for f in interSolid.Faces if isinstance(f, DB.PlanarFace) and f.FaceNormal.IsAlmostEqualTo( view.ViewDirection)), key = lambda x : x.Area)
    # get the curloop
    curveloop_shape = max(face.GetEdgesAsCurveLoops(), key=lambda c : c.GetExactLength())
    # add margin
    curveloop_shape_offset = DB.CurveLoop.CreateViaOffset(curveloop_shape, margin, face.FaceNormal)
    OUT =  face.ToProtoType()

there is a bug with CPython/PythonNet 2.5.x (inheritance problem in the function parameter) but should be manageable with Reflection