pyRevit

Code

Library

Get CropBox.Id

Simple

When you create a View in Revit it also creates CropBoxes as separate objects. And it means that CropBox Id relates to View Id and it always has the same difference.

So, here is the trick:

Get Id of a view and then increment it by 2 to get ElementId of a CropBox. That's it.

e.g.
view.Id = 13642
cropbox.Id = 13642 + 2

Here is a simple code snippet to test:

# Get View
view = doc.ActiveView

# Get CropBox Id (View.Id + 2)
int_view_id = int(str(view.Id))         # Id -> Integer
cropbox_id  = ElementId(int_view_id + 2)



Advanced

Here is a more complicated alternative that also works.

def get_cropbox_id(view):
    """Function to get cropbox_id of a given view."""
    provider     = ParameterValueProvider(ElementId( int(BuiltInParameter.ID_PARAM)) )
    rule         = FilterElementIdRule(provider, FilterNumericEquals(), view.Id)
    param_filter = ElementParameterFilter(rule)
    collector    = FilteredElementCollector(doc).WherePasses(param_filter).ToElementIds()
    if collector:
        for id in collector:
            if id != view.Id:
                return id

⌨️ Happy Coding!
Erik Frits