Elevation CropBox

Does anyone know how to change the CropBox Lineweight through the api? To accomplish this manually the only way I know of is to select the CropBox, right click and select “Override Graphics in View” → “By Element”. Make sure thin lines is turned off. The tedious part is doing this on many Interior Elevation CropBoxes.

Something rough I did a while back:

from pyrevit import revit, DB, forms, script

output = script.get_output()

doc = revit.doc

views = DB.FilteredElementCollector(doc).OfCategory(
views_on_sheet = []
for v in views:
        if v.get_Parameter(DB.BuiltInParameter.VIEWER_SHEET_NUMBER).AsString() != '':
selected_views = forms.SelectFromList.show(
    views_on_sheet, button_name='Select Views', multiselect=True, name_attr='Name')

lineweights = range(1, 17, 1)
selected_lineweight = forms.SelectFromList.show(
    lineweights, button_name='Select Lineweight', multiselect=False, height=475)

if selected_lineweight and selected_views:
    override = DB.OverrideGraphicSettings().SetProjectionLineWeight(selected_lineweight)
    with revit.TransactionGroup('Set Viewport Lineweight'):
        for view in selected_views:
            with revit.Transaction('TEMP crop box to false'):
                view.CropBoxVisible = False
            collector = DB.FilteredElementCollector(doc, view.Id)
            shownElems = collector.ToElementIds()
            with revit.Transaction('TEMP crop box to true'):
                view.CropBoxVisible = True
            collector = DB.FilteredElementCollector(doc, view.Id)
            cropBoxElement = collector.FirstElement()
            if cropBoxElement:
                with revit.Transaction('Set Viewport Lineweight'):
                    view.SetElementOverrides(cropBoxElement.Id, override)

Thanks for your reply. So it appears the issue is getting the cropbox Id. I am wondering why CropBox.Id does not work. Your method of comparing a collector list with and without the cropbox visible makes sense. I tried that and it worked for one of the views, but it did not work for the other three. I will have to dig in some more to see what is going on for the other three views on the elevation marker.

It appears that the CropBox.Id is 1 less than the View.Id. This worked for all of the views on the elevation marker. This might be a risky method, but seems to work as of now.

cb_id = view.Id.IntegerValue - 1
cb_id = DB.ElementId(cb_id)

Apply the override settings to the crop box

view.SetElementOverrides(cb_id, override_settings)