Camera zoom and orientation compatibility between 2D and 3D views

Camera zoom and orientation compatibility between 2D and 3D views

Anonymous
Not applicable
1,284 Views
2 Replies
Message 1 of 3

Camera zoom and orientation compatibility between 2D and 3D views

Anonymous
Not applicable

I'm developing an application for Revit 2016 and i'm using view3D.SetOrientation() and ZoomAndCenterRectangle() to save a camera position and zoom. Then if i want to go back to this position i press a Button.

It works pretty well in a 3DView, between 3D views or in a 2D View, between 2D views with the same section (top view lvl1, top view lvl2...).

But, when i save the orientation in a 3D view and use it in a 2D view (or from top sections to side sections) the view seems to show a somewhere else.
Is this somewhere else totally random or is it a way to correct the XYZ points to show the same thing between 3D and 2D views ?

Thanks a lot to the community, you guys already help me a lot to get into the revit api and this is the first time i feel the need to post something by myself.

0 Likes
Accepted solutions (1)
1,285 Views
2 Replies
Replies (2)
Message 2 of 3

Mustafa.Salaheldin
Collaborator
Collaborator

please provide a sample revit project and your sample code so I can help.

Note also that you have to save the orientation first in order to be able to apply it again.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

Thanks for your reply but i already get the answer ! 
For those who wondering : I get the camera orientation this way :

ViewOrientation3D direction = new ViewOrientation3D(eyePosition, upDirection, forwardDirection);
if (view is View3D)
{
direction = CameraParameter.GetOrientation(view3D);
}
else
{
ViewOrientation3D direction2D = new ViewOrientation3D(eyePosition, view.UpDirection, -view.ViewDirection);
}

And i set it this way :

XYZ AnyPointOnActiveView = new XYZ((doc.ActiveView.get_BoundingBox(doc.ActiveView).Max.X - doc.ActiveView.get_BoundingBox(doc.ActiveView).Min.X) / 1000,
                    (doc.ActiveView.get_BoundingBox(doc.ActiveView).Max.Y - doc.ActiveView.get_BoundingBox(doc.ActiveView).Min.Y) / 1000,
                    (doc.ActiveView.get_BoundingBox(doc.ActiveView).Max.Z - doc.ActiveView.get_BoundingBox(doc.ActiveView).Min.Z) / 1000);

double dirForX = Math.Abs(Math.Round(direction.ForwardDirection.X, 2));
                double dirForY = Math.Abs(Math.Round(direction.ForwardDirection.Y, 2));
                double dirForZ = Math.Abs(Math.Round(direction.ForwardDirection.Z, 2));

if (view is View3D)
                {
                    view3D.SetOrientation(direction);
                }
                else
                {
if ((dirForZ >= dirForX) && (dirForZ >= dirForY))
                    {
                        XYZ pproj = new XYZ(pp.X + ((AnyPointOnActiveView.Z - pp.Z) / direction.ForwardDirection.Z) * direction.ForwardDirection.X,
                            pp.Y + ((AnyPointOnActiveView.Z - pp.Z) / direction.ForwardDirection.Z) * direction.ForwardDirection.Y,
                            AnyPointOnActiveView.Z);
                        XYZ qproj = new XYZ(qq.X + ((AnyPointOnActiveView.Z - qq.Z) / direction.ForwardDirection.Z) * direction.ForwardDirection.X,
                            qq.Y + ((AnyPointOnActiveView.Z - qq.Z) / direction.ForwardDirection.Z) * direction.ForwardDirection.Y,
                            AnyPointOnActiveView.Z);
                        uiview.ZoomAndCenterRectangle(pproj, qproj);
                    }
//Same thing with (dirForY > dirForZ) && (dirForY > dirForX) and (dirForX > dirForY) && (dirForX > dirForZ) 
                    
                }

Thank you Revitalizer for this answer and sanjaymann for AnyPointOnActiveView

For Detail answer please send me a private message !

0 Likes