Finding the Center of a View... not a Viewport

Why does it seem so difficult to find the center of a View? Driving me nuts. Ultimately, I want to place a GA in the center of the view crop.

Python and the View Class gets me the CropBox Max and Min, the Origin, and View, Up, and Right directions (Outline seems to refer to its sheet size?) but the points don’t line up with the view in the World CS. I thought transforming the points to the CS of the view would get me there and it does get me closer but still, there are issues. I need to accommodate for an inverted Z axis in the CS and if the view is a section rather than an elevation I also have to rotate the GA depending on it’s View Direction (or at least I think that’s the determining factor).

What am I missing? I’m really hoping there’s an easier solution… or at least one that I can implement reliably.

View Helper.dyn (114.8 KB)

Why not use the Viewport.GetBoxCenter() method in the Revit API to extract the centre point of the viewport then use it as the constructor (placement point) of the new viewport (assuming you are working with placed views)?

I thought Viewport was different from View… no? Off to check.

Correct, viewports are typically found on sheets. Another solution might be to define a scope box then apply to new/existing views.

I’d need a scope box for each view… or one that I create and then delete after.

Okay then, how do I create a scopebox that matches my view? Once I have one I assume I average the Min/Max?

If you’re familiar with Python and the Revit API then you want to look at the ViewCropRegionShapeManager class. There are methods in there for cropping views using a CurveLoop which you can extract from an existing crop. If that is going to prove too challenging or time consuming, then …its a Revit workflow and a crop box can be assigned to a View Template.

1 Like

Thanks. I’ll look into it. Wouldn’t say I know either but I’m working on it!

The current workflow is to just place the GA and eye-ball it into position. I’m hoping to automate it.

That was so much easier it makes me sick.

I wasn’t sure what to do with the Autodesk.Revit.DB.Lines I got out of the Python script so I converted them to Drafting Lines to pull the curves and then deleted the Drafting Lines. I’m sure there’s another way but I haven’t figured it out yet. Thoughts?

I’ve still got some things to iron out but this was a huge help. Thanks!

1 Like

Hi @Greg_McDowell,

I encounter a similar problem, I am trying to locate my “view” (not viewport), I am wondering whether you have come up with some solution at the end?

And is there a way to convert “view” to “viewport”?