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