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:
- Create a crop box around a selected room in an elevation view.
- Ensure that the crop box adjusts itself to match the size and position of the room.
- 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)
Hi,
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
import clr
import sys
import System
from System.Collections.Generic import List
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("System.Reflection")
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))
lstCurveLoop.Add(curveLoop)
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):
TransactionManager.Instance.EnsureInTransaction(doc)
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)
crsm.SetCropShape(curveloop_shape_offset)
#interSolid.Dispose()
results.Dispose()
TransactionManager.Instance.TransactionTaskDone()
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
3 Likes