Get vector values from view cube Inventor API

Get vector values from view cube Inventor API

karolis.s
Advocate Advocate
558 Views
5 Replies
Message 1 of 6

Get vector values from view cube Inventor API

karolis.s
Advocate
Advocate

Hello. 

I need to get / create a UCS based on default TOP value of the view cube. (End Task is to store this matrix to SQL DB and read it from Fusion)

So it means
zVector: normal of kTopViewOrientation
xVector: normal of kRightViewOrientation
yVector: normal of kBackViewOrientation

 

@kandennti 

karoliss_0-1690308368639.png

 

 

I have tried to change camera view, apply it, than read UpVector properties, but I do not get expected values..
I have also tried to simply use  camera.ModelToViewTransformation matrix, but again I do not get expected values mentioned above..

Any ideas? Thank you.


0 Likes
Accepted solutions (1)
559 Views
5 Replies
Replies (5)
Message 2 of 6

Andrii_Humeniuk
Advisor
Advisor

Hi @karolis.s . I wrote iLogic code that creates a UserCoordinateSystem in the PartDocument according to the ViewBox coordinates. I hope this example helps you.

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim oUCSs As UserCoordinateSystems = oDoc.ComponentDefinition.UserCoordinateSystems
Dim oUCS As UserCoordinateSystem
Dim oCamera As Camera = oDoc.Views.Item(1).Camera
Dim oUCSDef As UserCoordinateSystemDefinition
Try
	oUCS = oUCSs("new UCS")
	oUCS.Transformation = oCamera.ModelToViewTransformation
Catch
	oUCSDef = oUCSs.CreateDefinition()
	oUCSDef.Transformation = oCamera.ModelToViewTransformation
	oUCS = oUCSs.Add(oUCSDef)
	oUCS.Name = "new UCS"
End Try

 

UCS.png

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 6

Michael.Navara
Advisor
Advisor

Try this code

 

Dim cam As Camera = ThisApplication.ActiveView.Camera

cam.ViewOrientationType = ViewOrientationTypeEnum.kRightViewOrientation
Dim x As Vector = cam.Target.VectorTo(cam.Eye)

cam.ViewOrientationType = ViewOrientationTypeEnum.kBackViewOrientation
Dim y As Vector = cam.Target.VectorTo(cam.Eye)

cam.ViewOrientationType = ViewOrientationTypeEnum.kTopViewOrientation
Dim z As Vector = cam.Target.VectorTo(cam.Eye)


Logger.Debug("x = [{0:N2}, {1:N2}, {2:N2}]", x.X, x.Y, x.Z)
Logger.Debug("y = [{0:N2}, {1:N2}, {2:N2}]", y.X, y.Y, y.Z)
Logger.Debug("z = [{0:N2}, {1:N2}, {2:N2}]", z.X, z.Y, z.Z)
0 Likes
Message 4 of 6

karolis.s
Advocate
Advocate

I have tried this method, it was the closest I could to the end result.. But Z axis is flipped on the part where origin is similar to wanted end result.. 

karoliss_0-1690361544707.png  

And if origin Z axis is looking to other direction than top I get totally wrong output..

 

karoliss_2-1690361869875.png  

karoliss_3-1690361896442.png

 

 

 

0 Likes
Message 5 of 6

karolis.s
Advocate
Advocate

Thank you for your time.

This way is also not giving me end result

karoliss_0-1690362052402.png

 

Message 6 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

I depends on how you create the UCS

In my opinion it works as expected

 

 

Dim part As PartDocument = ThisDoc.Document
Dim cam As Camera = part.Views(1).Camera

cam.ViewOrientationType = ViewOrientationTypeEnum.kRightViewOrientation
Dim x As Vector = cam.Target.VectorTo(cam.Eye)

cam.ViewOrientationType = ViewOrientationTypeEnum.kBackViewOrientation
Dim y As Vector = cam.Target.VectorTo(cam.Eye)

cam.ViewOrientationType = ViewOrientationTypeEnum.kTopViewOrientation
Dim z As Vector = cam.Target.VectorTo(cam.Eye)


Logger.Debug("x = [{0:N2}, {1:N2}, {2:N2}]", x.X, x.Y, x.Z)
Logger.Debug("y = [{0:N2}, {1:N2}, {2:N2}]", y.X, y.Y, y.Z)
Logger.Debug("z = [{0:N2}, {1:N2}, {2:N2}]", z.X, z.Y, z.Z)

'Create UCS
Dim origin As Point = ThisApplication.TransientGeometry.CreatePoint()

Dim mtx As Matrix = ThisApplication.TransientGeometry.CreateMatrix()
mtx.SetCoordinateSystem(origin, x, y, z)

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

part.ComponentDefinition.UserCoordinateSystems.Add(ucsDef)