How to bulk override Crop Region line style for Viewports on Sheets?

Hi everyone,

I’m looking for a robust way to bulk override the Crop Region (OST_CropBoundary) line style for selected Viewports on a Sheet using the Revit API/pyRevit.

Standard SetCategoryOverrides and SetElementOverrides seem to fail or be restricted when applied to Crop Regions of Section/Elevation views placed on Sheets. However, I’ve seen this functionality in existing tools (like Jean-Marc Couffin’s), so I know it’s possible.

Does anyone have a recommended approach or a snippet to achieve this?

Thanks in advance!

Set Element Overrides should work. How are you collecting the crop regions and/or views? An example, below of collecting the crop region -though there is likely a better method nowadays. Then you should just be able to use the view element just set the element overrides.

def get_view_crop_box(view):
transaction_group = DB.TransactionGroup(doc, "Temp to find crop box element")
transaction_group.Start( )

t1 = DB.Transaction(doc, "Temp to find crop box element")
t1.Start( )
view.CropBoxVisible=False
t1.Commit( )

shown_elements=DB.FilteredElementCollector(doc, view.Id).ToElementIds( )

t2.Start( )
view.CropBoxVisible=True
t2.Commit( )

crop_box = DB.FilteredElementCollector(doc, view.Id).Excluding(shown_elements).FirstElement( )
transaction_group.RollBack( )
return crop_box

......

crop_regions = []
graphic_settings = DB.OverrideGraphicSettings( )
graphic_settings.SetProjectionLineWeight(line_weight)

for view in selected_views: #type: DB.View
try:
crop_region = get_view_crop_box(view)
crop_regions.append (crop_region)
except:
crop_regions.append (None)
print ("COULD NOT GET CROP REGION",view.Name)

with Transaction('Set Elevation Crop LineWeight',doc):
for elevation_view,region in zip(selected_views, crop_regions):

elevation_view.CropBoxVisible = True
crop_region_id = region.Id
elevation_view.SetElementOverrides(crop_region_id, graphic_settings)

1 Like