Reading ViewOrientation3D from an Active Isometric View

Reading ViewOrientation3D from an Active Isometric View

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

Reading ViewOrientation3D from an Active Isometric View

Anonymous
Not applicable

Hi, 

 

I have a problem I need to solve, I want to create an application that automatically generates floorplans from levels. 

Creating the 3D views, the section boxes and reading the levels this seems to go all smoothly using the API.

 

However I dont seem to be able to find a way to GET the current ViewOrientation3D property values (eye, up, forward) settings. So I can set these and then copy them to each new 3D view created, a new 3D view seems to just open on default settings and the API manual seens to give any way of providing this.

 

So i'm looking for a working code like:

 

XYZ eye = new XYZ(ActiveView.ViewOrientation3D.eye);
XYZ up = new XYZ(ActiveView.ViewOrientation3D.up);
XYZ forward = new XYZ(ActiveView.ViewOrientation3D.forward);

 

ViewOrientation3D new3dviews = new ViewOrientation3D(eye, up, forward);

 

I know this code cant work now, but just to be clear:

I'm looking for a way to READ the current ViewOrient3D settings (if ViewType = ViewType.ThreeD of course) so I can copy them to the next created 3D isometric view. 

 

Thanks

 

 

 

 

 

 

 

0 Likes
1,058 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Okay, so I created myself an answer by studying the uidoc.ActiveView.Updirection, ViewDirection and RightDirection.

These are NOT similar as the ViewOrientation3D values, BUT one can convert these to one and another. 

 

Lets have a look:

 

After creating a series of views and then reading the view properties, one can see that there is a certain correlation between these two.

 

ViewOrientationView.jpg

The eyePosition can be set as 0,0,0

In fact the ActiveView.UpDirection is fully similary to the "upDirection" value in the ViewOrientation3D

Then the "forwardDirection" can be calculated as the "inverted" value of ActiveView.ViewDirection.

 

And this gives us the following code to get the ActiveView ViewOrientation3D settings.

 

public ViewOrientation3D GetCurrentViewOrientation(UIDocument uidoc)
        {
            // Use this code to create a ViewOrientation from the active isometric view
            // In previous code it should been verified that one is in fact in a active view
            // In every other plan it will simply retun a (1,0,0;0,1,0;0,0,1) valu.
                 
            XYZ UpDir = uidoc.ActiveView.UpDirection;           //Defines your UpDirection
            XYZ ViewDir = uidoc.ActiveView.ViewDirection;       //Defines your ViewDirection
            XYZ ViewInvDir = InvCoord(ViewDir);                 //Defines your Invert of your ViewDirection
            //XYZ RightDir = uidoc.ActiveView.RightDirection;   //Not used
                       
            XYZ eye = new XYZ(0, 0, 0); //This is always 0,0,0 (unless perspective view is set)
            XYZ up = UpDir; //up is equal to UpDirection in activeview
            XYZ forward = ViewInvDir; //forward is the inverted value of ViewDirection.

            //bundle them in a nice package:
            ViewOrientation3D MyNewOrientation = new ViewOrientation3D(eye, up, forward);

            //And there you go:
            return MyNewOrientation;
        }

        public XYZ InvCoord(XYZ MyCoord)
        {
            //Some code to "Invert" the values of the given coordinate
            //Invert this point:
            XYZ invcoord = new XYZ((
                Convert.ToDouble(MyCoord.X * -1)),
                (Convert.ToDouble(MyCoord.Y * -1)),
                (Convert.ToDouble(MyCoord.Z * -1)));

            //And there you go:
            return invcoord;
        }

 

With a ViewOrientation3D viewOrientation3D = GetCurrentViewOrientation(uidoc)

you should get the active IsometricView ViewOrientation3D settings.

 

Is this usefull? I think so, it will allow you to get a camera point from the user before starting the restof the code.

I can now finish my Isometric View Floor-plate generator code....

 

 

 

0 Likes
Message 3 of 3

Ning_Zhou
Advocate
Advocate

hi David, i'm still trying to figure out these stuff ...
from your code:
XYZ eye = new XYZ(0, 0, 0); //This is always 0,0,0 (unless perspective view is set)
XYZ up = UpDir; //up is equal to UpDirection in activeview
XYZ forward = ViewInvDir; //forward is the inverted value of ViewDirection.

eye is OK, but i'm a bit confused w/ up and forward

i have the following code which basically create front Isometric view and front Perspective view, see attached JPGs, but i don't know why up uses (0, 0, 1) and forward uses (0, 1, 0)? well, what i really needed is the graphic similar to Projection.jpg w/ up and forward arrow added.

View3D view3D = View3D.CreateIsometric/*CreatePerspective*/(doc, new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast<ViewFamilyType>().FirstOrDefault<ViewFamilyType>(x => x.ViewFamily == ViewFamily.ThreeDimensional).Id);
if (view3D != null)
 {
   XYZ eye = new XYZ(0, -100, 10);
   XYZ up = new XYZ(0, 0, 1);
   XYZ forward = new XYZ(0, 1, 0);
   view3D.SetOrientation(new ViewOrientation3D(eye, up, forward));
   //view3D.get_Parameter("Far Clip Active").Set(0);
}

0 Likes