Inventor: Camera, Action!

June 1, 2022 Randall Mabery

At times, you may find yourself wanting to control the Inventor camera.  This may be when you are automating the configuration of parts and assemblies or maybe as part of a design review.  In this blog post, we'll take a look at a few different ways to accomplish this.

Camera Object

The Camera object can be used in multiple document types or view types but we're going to be discussing using the camera against the active view of a part or assembly document.

The first thing we need to do is get the active camera object.

Dim oCamera As Camera
oCamera = ThisApplication.ActiveView.Camera

Applying changes to the camera

When changes such as view orientation are made to the camera, they'll need to be applied to the camera for the changes to take effect.  There are two methods for accomplishing this against the camera object:

  • Apply: will cause the changes to take effect
  • ApplyWithoutTransition: will cause the changes to take effect without a transition (instantly)

In the snippets below, you'll see that I'm using the Apply method.

View Orientation

The Inventor camera has multiple pre-defined view orientations which are accessed through the ViewOrientation type property of the camera object.  Some of the more common orientations are kFrontViewOrientation, kRightViewOrientation..... you can probably figure out the rest.  These are listed in the ViewOrientationTypeEnum Enumerator.

oCamera.ViewOrientationType = kFrontViewOrientation
oCamera.Apply

Perspective

The camera object has a boolean property called Perspective that can be used to control whether the camera is in Orthographic (the Perspective property is set to false) or Perspective mode (the Perspective property is set to true) .

oCamera.Perspective = True 
oCamera.Apply

Perspective With Ortho Faces

My favorite projection to work in Inventor is Perspective with Ortho Faces.  Unfortunately, there is currently no way to set this as the default mode as you can set Orthographic or Perspective.  This mode can be accessed using automation.  We need to grab the ControlDefinition for the command and execute it.

 

Dim oControlDef As ControlDefinitions
oControlDef = ThisApplication.CommandManager.ControlDefinitions

If oCamera.Perspective = True Then 
	oControlDef.Item("AppViewCubePerspectiveOrthoCmd").Execute 
End If

I have a rule that utilizes this that's set to the Event Triggers of New Document and After Open Document.  This is my workaround until we are able to set the Projection in the Application Options \ Display tab \ Settings dialog box.

Zoom To Selected Component

When configuring assemblies, I sometimes move the camera around so the user can see what's happening. As usual, there are many ways this can be accomplished.  The most direct is to select the component and then Zoom Selected.

For the example below, the assembly has a multi-value parameter named "Components".  This parameter lists the various components in the assembly.  This code should be treated separately from the snippets above.

Sub Main()
	' Declarations
	Dim oAssyDoc As AssemblyDocument
	oAssyDoc = ThisApplication.ActiveDocument

	Dim oAssyCompDef As AssemblyComponentDefinition
	oAssyCompDef = oAssyDoc.ComponentDefinition
	
	' Get component name
	Dim sCompName As String
	sCompName = Parameter("Components")
	
	' Get occurrence
	Dim oOcc1 As ComponentOccurrence
	oOcc1 = Component.InventorComponent(sCompName)

	' Select selected occurrence
	Dim oSS As SelectSet
	oSS = ThisApplication.ActiveDocument.SelectSet
	
	oSS.Select(oOcc1)
	
	' Zoom Selected
	Dim oControlDef As ControlDefinitions
	oControlDef = ThisApplication.CommandManager.ControlDefinitions

	oControlDef.Item("AppZoomSelectCmd").Execute
	
	' Clear Selection
	oSS.Clear
End Sub

In future posts, I'll discuss using the Camera objects Eye and Target properties to allow even more control over the camera.

About the Author

Randall Mabery

I love the technology, thoroughly enjoy helping people find solutions and believe in the software. I train individuals in the use of Autodesk design software such as Inventor and AutoCAD. The most satisfying part of my job is working on automation solutions for clients, assisting them in streamlining their design process and automating tasks.

Follow on Linkedin More Content by Randall Mabery
Previous Article
Inventor: Formatting Parameters for Custom iProperties
Inventor: Formatting Parameters for Custom iProperties

Customize the text formatting of Autodesk Inventor's exported parameters.

Next Article
Inventor 2023: iLogic Rules & Forms On The Ribbon
Inventor 2023: iLogic Rules & Forms On The Ribbon

Inventor 2023 doesn't have a lot of new iLogic tools but we now have the ability to add external rules and ...