In Revit, the View and the CropBox have different element Ids. If I want override the crop region outline in a given view, I need to get the cropbox outline in the view. Unfortunately, it has the same Category and Type as the View. I can’t find an api method to get the CropBox from the View. However, by coincidence I realised that the view CropBox element almost always has an ElementId one ‘less’ than the View itself. I know this method is bad (could be unpredictable), so I’m still looking for a better way. Does anyone know correct API process to get the CropBox ‘element’ from the View?
Note: this method was actually successful, I just want it to be more safe:
Awesome Dimitar! Thanks.
What would be the best way to map a given View to these Elements. View Name might be too generic?
The view name seems to be the only thing connecting them. It should also be a pretty robust option because view names must be unique.
You could try the following to get the view from the crop element:
if you got a view and want to find the crop box element for that view there is another option:
you can turn off the crop box (view.CropBoxVisible = False)
then select all elements in a view using the FilteredElementCollector(doc, view.id).ToElementIds()
Then the CropBox back on
Finally use the FilteredElementCollector(doc, view.id).Excluding(element ids from first collector).FirstElement()
That should give you the CropBox Element.
I packaged up Dimitar’s code and the view name matching method into this node:
Have a look at this post as well: