Issue
I want to set a view orientation for parts and assemblies from my Inventor AddIn that does not correspond with the 'standard' orientations defined from the user interface like the Top/Front/Side/Iso views. How do I do this?
Solution
The solution is to use the Camera Object. The Inventor API help files illustrate how to set up a standard view - look at the documentation for the Camera object.
The code below illustrates how you would set up an arbitrary view orientation using the Eye, Target and UpVector properties of the Camera object.
C#
private void AdjustCamera()
{
TransientGeometry oTG = m_inventorApp.TransientGeometry;
Inventor.View oView = m_inventorApp.ActiveView;
Inventor.Camera oCamera = oView.Camera;
// set Camera Eye
Inventor.Point oEye
= oTG.CreatePoint(0, 0, 0);
oCamera.Eye = oEye;
// set Camera Target
Inventor.Point oTarget
= oTG.CreatePoint(-1, -1, -1);
oCamera.Target = oTarget;
// set Camera UpVector
UnitVector oUpVector
= oTG.CreateUnitVector(1, 1, 0);
oCamera.UpVector = oUpVector;
// Apply camera settings
oCamera.Apply();
}
VB .NET
Sub Adjust_Camera()
Dim oTG As TransientGeometry _
= m_inventorApp.TransientGeometry
Dim oView As View = m_inventorApp.ActiveView
Dim oCamera As Camera = oView.Camera
' set camera Eye
Dim oEye As Inventor.Point _
= oTG.CreatePoint(0, 0, 0)
oCamera.Eye = oEye
' set camera Target
Dim oTarget As Inventor.Point _
= oTG.CreatePoint(-1, -1, -1)
oCamera.Target = oTarget
' set camera UpVector
Dim oUpVector As UnitVector _
= oTG.CreateUnitVector(1, 1, 0)
oCamera.UpVector = oUpVector
' apply camera settings
oCamera.Apply()
End Sub
VBA
Sub Adjust_Camera ()
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
Dim oView As View
Set oView = ThisApplication.ActiveView
Dim oCamera As Camera
Set oCamera = oView.Camera
Dim oEye As Inventor.Point
Set oEye = oTG.CreatePoint(0, 0, 0)
oCamera.Eye = oEye
Dim oTarget As Inventor.Point
Set oTarget = oTG.CreatePoint(-1, -1, -1)
oCamera.Target = oTarget
Dim oUpVector As UnitVector
Set oUpVector = oTG.CreateUnitVector(1, 1, 0)
oCamera.UpVector = oUpVector
oCamera.Apply
End Sub