Set Crop Region for ceiling plans not working

Hi all! Long time reader, first ime poster :slight_smile:
I’ve encountered strange difficulties with setting crop region for ceiling plan using the CropRegionShapeManager class in Revit API
The task I’m trying to accomplish is to take a collection of Rooms (one apartment), find the overall boundary (by offsetting Room Boundaries, merging shapes and offsetting back), and create a set of new plans cropped to the outline.
The method works fine for Floor plans, all new plans have the boundary applied, but with the ceiling plan I receive the error: “InvalidOperationException: The crop of the associated view is not permitted to have a non-rectangular crop”.
I can set the region to be any shape through the UI but not through the script.
I’ve tried also moving the boundary curves to the Ceiling plan Cut plane, view range top in hopes that the elevation of the Curve Loop matters, but to no avail.
Here’s the python script:

import clr
import sys
import System
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

boundaries = IN[0]
views = UnwrapElement(IN[1])

lines = []

segments = [b.ToRevitType() for b in boundaries]
cl = CurveLoop()

for s in segments:
    cl.Append(s)


for view in views:

    if view is not None:
    
        TransactionManager.Instance.EnsureInTransaction(doc);
        
        vcm = view.GetCropRegionShapeManager()
        
        try:
            vcm.SetCropShape(cl)

        except:
            #trying to move segments to View plane
            vr = view.GetViewRange()
            offset = vr.GetOffset(PlanViewPlane.CutPlane)
            ceiling_curve_loop = CurveLoop()
            
            for s in segments:

                start = s.GetEndPoint(0)
                new_start = XYZ(start.X, start.Y, start.Z +  offset)
                end = s.GetEndPoint(1)
                new_end = XYZ(end.X, end.Y, end.Z +  offset)
                sc = Line.CreateBound(new_start, new_end)

                ceiling_curve_loop.Append(sc)
                lines.append(sc.ToProtoType())
                
            # This line produces error    
            #vcm.SetCropShape(ceiling_curve_loop)

        TransactionManager.Instance.TransactionTaskDone();    
OUT = views, lines


image

The region in question is also both planar and closed.
Any ideas would be greatly appreciated :slight_smile:

Ok, I found the answer - the reason crop shape could not be set was because the ceiling plan was a newly created view - the ViewCropRegionShapeManager.CanHaveShape is False until Crop region has been made visible. Once Crop has been enabled SetCropShape works