Get CropBox Element from a View Element

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:

https://knowledge.autodesk.com/community/screencast/de0790ad-6a76-47b7-a08b-1871f112b163

Hi Luke,

You’ll find those elements if you probe the built in Viewers category:

1 Like

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:

Or this if you want to get the crop element from the view:

 

 

1 Like

if you got a view and want to find the crop box element for that view there is another option:

  1. you can turn off the crop box (view.CropBoxVisible = False)

  2. then select all elements in a view using the FilteredElementCollector(doc, view.id).ToElementIds()

  3. Then the CropBox back on

  4. Finally use the FilteredElementCollector(doc, view.id).Excluding(element ids from first collector).FirstElement()

 

That should give you the CropBox Element. :slight_smile:

I packaged up Dimitar’s code and the view name matching method into this node:

http://dynamonodes.com/2016/02/12/get-crop-box-list-from-view-list/

Have a look at this post as well: