Dec 1, 2020
Get CropBox Id in Revit with Python.
Learn how to get CropBox Id in Revit API.
The first method is quite straight forward and goes like this:
Hide the CropBox
Use FilteredElementCollector(doc, view_id) to collect all elements you can see in the view.
Unhide the CropBox
Use FilteredElementCollector again, but this time exclude elements you collected the first time with .Excluding(element_ids)
Get ElementId of the CropBox from the collection.
This method is a bit messy because of multiple transactions. So I have another option.
I have found an article by Jeremy Tammik - "Efficiently Retrieve Crop Box for Given View" in C#.
So I've translated it to python for people who don't "speak" C# well enough. I encourage you to read his article to better understand the logic behind this function.
Be aware that FilteredElementCollector will grab CropBox and View so be aware of that.