Crop boxes for views (C#)

I’m trying to get point x
1 is the annotation crop
2 is the crop box
x is the top left of the crop box
3 is the top left of the viewport.

First image is when i’m in view and can see crop and anoatation crop.
Second image is when I am on the sheet and select the viewport.

Outline childOutline = childViewport.GetBoxOutline();

The outline seems to be the viewport … which doesn’t correspond to either of the other crops.

Any idea how to get just the crop?
The crop in relation to paperspace.

Don’t work with the viewport - work with the view.

Something like IList<CurveLoop> cropCrvs = view. GetCropRegionShapeManager().GetCropShape();

From there you and decipher how you want to define that point relative to all the curves.

I tried getting crop shape… but how to translate coordinates to sheet coordinates?

@Alien it baffled me years ago. iirc, u can try this (simply ignore OOP parts, irrelevant)

this.View = view;
var cBox = this.View.CropBox;
this.width = cBox.Max.X - cBox.Min.X;
this.height = cBox.Max.Y - cBox.Min.Y;
this.width /= this.View.Scale; height /= this.View.Scale;

then Viewport.GetBoxCenter(). u know, center is center.

translate center with the width and height u’ve just got (sheet space).

2 Likes

Oooo… not a bad idea. Right I’ll try that :slight_smile:
Thanks.
.
.
.
Watch this space :smiley:

2 Likes

tell u what, this isn’t over. this was probably an attempt from around rvt 16, maybe even earlier. i remember vp/view manipulation within sheet space had some very interesting/weird issues. i haven’t checked on whether supports for sheet space has improved in newer versions like 25/26. so it’s best to keep problems within model space if possible.

a bit blah. this brings back some wonderful memories. i was staring at this blue frame for days back then. 10 years.., man im aging.

1 Like

Hmm.. doesn’t seem to help.

Yes I can get size of view… Also get BB of view…
But I can’t seem to convert it to sheet coordinates.

strange. i remember once scale comes into play, that gives sizes in sheet space. and the box center is in sheet space already.

edit: wait, once divided by scale, there’s no conversion anymore. they should be all in sheet space i think.

and another thing, check the title block if u see some weird numbers. where the sheet space (0,0) locates and etc. maybe the coords u get is in sheet space but looks odd because of some mysterious shift of the entire sheet.

This might be relevant to your interests:

1 Like

I accounted for the possible titleblock shift already… It’s just I can’t seem to get point X in relation to the sheet.

Also relevant: Revit API 2026 Documentation

Keep pulling on the threads noted in the documentation in this and my previous link and you’ll get there. :slight_smile:

tbh i’ve just tested it on my machine, everythin works fine. :melting_face: but my brain is the mud right now factoring in the time difference with u guys. lets try figure it out some other time if u want to.

3 Likes

Sooo, turns out my code is working… However, the issue is it’s aligning to the cropped area shown when I click on the view, not the crop region that’s outlined (1).

How do I get it to align to the crop region outlined?

1 - crop region outlined
2 - Annotation crop
3 - The actual box it’s aligning to (this is the one that appears when you click on the viewport on the sheet)

It looks like your coordinates for the crop box are not mapped correctly. Try building a set of views around a pipe from (0,0,0) to (10,5, 15) using a different bounding box for each. All bounding boxes should have a min point of (-1,-1,-1), and the max points should be every permutation of (7, 12, 17). Something like [[7,12,17],[7, 17, 12], [12,7,17], [12,17,7], [17, 7, 12], [17, 12, 7]]; in design script should suffice. Name the views by the bounding box’s max point as a string, and you will likely be able to identify which box you want to use, which will allow you to identify how to construct your box.

You lost me.
I have crop box, annotation crop box… and what’s the other one? Viewport something ?

Ah - sorry I got vocab confused.

Seems you want the outline property, no?

Hard to see what is going wrong without a code sample to look at.

I am on a sheet and I have crop region visible. You can see the crop regions here. #1 arrows pointing to them

If I move my mouse over the view I get another box. #3 arrow pointing to it. And my script picks up the corners of this box and the corners of the other, “mouse over” boxes.

I want it to get box #1, not box #3

You need to the crop box from the “View” not the “Viewport” box outline.

Do watch out that the view crop box will probably be in a 3d space geometry and may not align with the viewport box outline. You may need to do some geometric adjustment to get them to overlay over each other.

2 Likes