Align open views to active view

Align open views to active view

tpover
Contributor Contributor
1,316 Views
5 Replies
Message 1 of 6

Align open views to active view

tpover
Contributor
Contributor

Hello everyone,

 

Recently I had a glance at Archicad and I noticed the way you could switch between floor plans while the size and position of the view remained the same. This way it's really easy to compare floor plans to each other. So I thought I would make a little add-in for Revit that can align all open views to the active view (obviously only works for floor/ceiling plans).

I found this post on the building coder: http://thebuildingcoder.typepad.com/blog/2012/06/uiview-and-windows-device-coordinates.html and came up with this small piece of code myself:

 

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            m_app = commandData.Application;
            Application app = m_app.Application;
            m_doc = m_app.ActiveUIDocument.Document;
            UIDocument uidoc = m_app.ActiveUIDocument;

            try
            {
                View aview = uidoc.ActiveView;
                IList<UIView> uiviews = uidoc.GetOpenUIViews();
                UIView uiview = null;
                IList<XYZ> rect = new List<XYZ>();

                foreach (UIView uv in uiviews)
                {
                    if (uv.ViewId.Equals(aview.Id))
                    {
                        uiview = uv;
                    }                   
                }
                rect = uiview.GetZoomCorners();

                foreach (UIView view in uiviews)
                {
                    view.ZoomAndCenterRectangle(rect[0], rect[1]);
                }

                return Result.Succeeded;
            }
            catch (Exception)
            {
                return Result.Failed;
            }

I retrieve the model coordinates with the GetZoomCorners method and the apply those same coordinates to the ZoomAndCenterRectangle method. What happens is that all views except the active view get aligned to each other, but on a slightly off position from the active view. Is there anyone who knows the underlying workings of either of the above methods? Maybe it has something to do with the size of the property/project browser window?

 

Any advice would be welcome.

 

-Taco

 

 

Accepted solutions (1)
1,317 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor

Try excluding active view from bottom loop where the views are being changed.

 

I could not tell you why that would work (in and out being different for the same rectangle). I can only guess that the two methods are not exactly the same in terms of rectangle ratio. If you are zooming to a rectangle and the UIView is not matching that original ratio then compatibility of rectangles must be found somehow with the ZoomAndCenterRectangle method.

.

0 Likes
Message 3 of 6

tpover
Contributor
Contributor

You must be right about the 2 methods having different rectangle sizes/ratios. I'm gonna debug/report on both methods and see if I can find something of a constant scaling factor I might be able to use. Thanks for the idea!

0 Likes
Message 4 of 6

tpover
Contributor
Contributor

So I dug a little further into it but i can't seem to find a constant scaling factor. The views also align with a weird offset every time. For testing purposes I created the same detail line rectangle on the 'host' view and on the view to align. This is the host view from which I run the add-in

align views host.png

 

And this is the view that should be aligned but failed to. Notice the diagonal detail line, that's a line between the host view's min and max points.

 

align views slave.png

 

Is there anyone that knows why there is a such a weird and big difference between the two?

 

0 Likes
Message 5 of 6

FAIR59
Advisor
Advisor
Accepted solution

I find that the uiview you want to change, needs to be the activeview.

Both GetZoomCorners and ZoomAndCenterRectangle will misbehave for a non activeview.

Message 6 of 6

tpover
Contributor
Contributor

Ah yes, that did the job. Thanks so much!

0 Likes