Retrieve View Cube directions from an assembly environment without opening Part Document

Retrieve View Cube directions from an assembly environment without opening Part Document

karolis.s
Advocate Advocate
214 Views
2 Replies
Message 1 of 3

Retrieve View Cube directions from an assembly environment without opening Part Document

karolis.s
Advocate
Advocate

Hello.

I am looking for a solution to improve my algorithm and I am not sure if it's possible to do that.

The task is to change part document iProperty from assembly environment. I am able to do that, but there are some conditions - I have to retrieve vectors from view cube and based on these vectors data I am changing an appropriate iProperties.

My current approach is to open part document -> retrieve vectors -> close part document.

This is the code which does the job when the part document is opened.

public static Matrix GetXYZVectorsFromViewCube(Inventor.View activeView)
        {
            TransientGeometry oTG = activeView.Application.TransientGeometry;

            Camera camera = activeView.Camera;

            camera.ViewOrientationType = ViewOrientationTypeEnum.kRightViewOrientation;
            Vector xVector = camera.Target.VectorTo(camera.Eye);

            camera.ViewOrientationType = ViewOrientationTypeEnum.kBackViewOrientation;
            Vector yVector = camera.Target.VectorTo(camera.Eye);

            camera.ViewOrientationType = ViewOrientationTypeEnum.kTopViewOrientation;
            Vector zVector = camera.Target.VectorTo(camera.Eye);

            Point origin = oTG.CreatePoint();
            Matrix mtx = oTG.CreateMatrix();
            mtx.SetCoordinateSystem(origin, xVector, yVector, zVector);

            return mtx;
        }



The question is:
Can I get the same result without opening part document (accessing camera View of active document), OpenVisible = False property is also not an option, because I get different / unexpected results.

Here is a related topic posted by me:
https://forums.autodesk.com/t5/inventor-programming-ilogic/get-vector-values-from-view-cube-inventor...

Thank you
Best regards,
Karolis Šarskus




0 Likes
215 Views
2 Replies
Replies (2)
Message 2 of 3

J-Camper
Advisor
Advisor

I would just get the vectors from the origin coordinate system.  It appears as though you are simply swapping the Y and Z axes, and you could get those without opening and manipulating the view cube.  It also avoids potential issues from end users changing the default view cube settings, unless you expect/want the view cube to be in a nonstandard state for your UCS. 

 

This is how to get the UCS but using the origin geometry:

Dim pdef As PartComponentDefinition = ThisDoc.Document.ComponentDefinition

'get origin objects
Dim origin As Point = pdef.WorkPoints.Item(1).Point 'set as origin center point
Dim xAxis As Vector = pdef.WorkAxes.Item(1).Line.Direction.AsVector 'set as origin x axis
Dim yAxis As Vector = pdef.WorkAxes.Item(3).Line.Direction.AsVector	'set as origin z axis
Dim zAxis As Vector = pdef.WorkAxes.Item(2).Line.Direction.AsVector	'set as origin y axis
'create matrix
Dim mtx As Matrix = ThisApplication.TransientGeometry.CreateMatrix()
mtx.SetCoordinateSystem(origin, xAxis, yAxis, zAxis)

Dim ucsDef As UserCoordinateSystemDefinition = pdef.UserCoordinateSystems.CreateDefinition()
ucsDef.Transformation = mtx

pdef.UserCoordinateSystems.Add(ucsDef)

 

0 Likes
Message 3 of 3

karolis.s
Advocate
Advocate

Well, we have to be able to change TOP view of view cube, because our drawings are generated based on this view and engineers cannot always predict which orientation would be the best fit.

0 Likes