Change Home View using iLogic code

Change Home View using iLogic code

Anonymous
Not applicable
6,749 Views
19 Replies
Message 1 of 20

Change Home View using iLogic code

Anonymous
Not applicable

I have a model which can be placed vertical or horizontal. I have made user parameters as Horizontal & Vertical. With these parameters i need to link and change the home view as per the selected option. For Vertical Z axis should face upwards and for Horizontal Y axis should face upwards.

Can anyone suggest me a code which can change and set the "Set Current View as Home"? Please see the attach picture for reference.

0 Likes
Accepted solutions (2)
6,750 Views
19 Replies
Replies (19)
Message 2 of 20

Vladimir.Ananyev
Alumni
Alumni

Hope this topic could help you

http://forums.autodesk.com/t5/inventor-customization/viewcube-rotation-through-api/m-p/5175541#M5106...


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 20

Anonymous
Not applicable

@Vladimir.Ananyev Well this command works pretty well for rotating my active view, this solves my half question. The remaining half question is how to make this new changed active view as my home view or you can say "Set Current View As Home" using iLogic code. Thanks for reply.

0 Likes
Message 4 of 20

Vladimir.Ananyev
Alumni
Alumni

You may try the following rule:

'Dim name As String = "AppViewCubeViewHomeFixedCmd"
Dim name As String = "AppViewCubeViewHomeFloatingCmd"
Dim oDef As ButtonDefinition = ThisApplication.CommandManager _
		.ControlDefinitions.Item(name)
oDef.Execute


How to get the full list of the Inventor command names is described here:

Running Commands Using the API

http://modthemachine.typepad.com/my_weblog/2009/03/running-commands-using-the-api.html

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 20

Anonymous
Not applicable

Yes that works for me, can you please suggest me enum value for FrontRightISO view?

0 Likes
Message 6 of 20

Vladimir.Ananyev
Alumni
Alumni

I’ve printed a list of all of the commands available in the Inventor 2015 (using the code provided by the article mentioned earlier).  Here are commands that are ready to use:

 

AppViewCubeCmd 
AppViewCubeHomeCmd
AppViewCubeOrthographicCmd
AppViewCubePerspectiveCmd
AppViewCubePerspectiveOrthoCmd
AppViewCubePropertiesCmd
AppViewCubeViewFrontCmd
AppViewCubeViewHomeFixedCmd
AppViewCubeViewHomeFloatingCmd
AppViewCubeViewLockCurrentSelectionCmd
AppViewCubeViewResetToFrontCmd
AppViewCubeViewTopCmd

 

View.Camera.ViewOrientationType property cpould be also useful.  See Inventor API Help for the ViewOrientationTypeEnum values available.

 

cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 7 of 20

Anonymous
Not applicable

I have found the following enum values but not able to find the FrontRightIso enum. Can you please suggest me for it?

 

'list of view enums:
' kTopViewOrientation = 10754
' kRightViewOrientation = 10755
' kBackViewOrientation = 10756
' kBottomViewOrientation = 10757
' kLeftViewOrientation = 10758
' kIsoTopRightViewOrientation = 10759
' kIsoTopLeftViewOrientation = 10760
' kIsoBottomRightViewOrientation = 10761
' kIsoBottomLeftViewOrientation = 10762
' kFrontViewOrientation = 10764

 

0 Likes
Message 8 of 20

Vladimir.Ananyev
Alumni
Alumni

 

ViewOrientationTypeEnum Enumerator

kIsoTopRightViewOrientation 10759 Isometric -- Top Right View.

Does it work for you?


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 9 of 20

Anonymous
Not applicable

10759 is for TopRightViewOrientation but i need for FrontRightViewOrientation.

0 Likes
Message 10 of 20

Vladimir.Ananyev
Alumni
Alumni

All predefined orientations are listed in the ViewOrientationTypeEnum enumerator.

Any other orientations you may get programmatically using Camera object functionality.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 11 of 20

Anonymous
Not applicable

Actually i dont know how to get the view ISO view.PNGFrontRightISO view using programmatically using Camera object functionality.

0 Likes
Message 12 of 20

MegaJerk
Collaborator
Collaborator

Depending on the version of Inventor that you're using, I actually would shy away from using the Camera function to change views, for now, unless you know that your code won't be used by someone who uses the Perspective View type instead of Orthographic. 

Why? 

Because I think that there is currently a bug with how Inventor (2015 and probably up I'd imagine) handles the math to change the Perspective Angle when the view is set to Perspective = True, and there are no visible occurrences on the screen. It essentially creates an overflow bug that will force a crash or create an instability, which is never fun. 

Recently I have reworked my view code to: 



Sub FitStageToScreen ()
 'Dim cam As Inventor.Camera 
 'cam = ThisApplication.ActiveView.Camera 
 'cam.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kIsoTopRightViewOrientation     
 'cam.Apply()
 'cam.Fit() 
 'cam.ApplyWithoutTransition() 
	
  Call ThisApplication.CommandManager.ControlDefinitions.Item("AppZoomAllCmd").Execute
  Call ThisApplication.ActiveView.GoHome	
End Sub 


I believe that this should accomplish what you are wanting to do. 

However, for those of you who would like to have a little fun crashing / messing with your session of inventor, feel free to use to use the following code to do so! (*** This actually should not cause any problems in 2012, but SHOULD cause a problem in 2015 and up. I'm not sure when it was introduced into Inventor, so if you have a version that is different from the ones listed above, it would actually be nice to get some feedback to find out if it's causing bad things to happen or not!) 

Imports Inventor.ViewOrientationTypeEnum


If ThisApplication.ActiveDocument.DocumentType _
<> kAssemblyDocumentObject Then
    MessageBox.Show ("Run from an Assembly!!!")
    Return
End If

' Set the current assembly to the active document 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

' Set the document's Assembly Component Definition

Dim oCompDef As AssemblyComponentDefinition
oCompDef = oDoc.ComponentDefinition

' Setting the Reps Manager

Dim oRepManager As RepresentationsManager
oRepManager = oCompDef.RepresentationsManager

' This used to test to see if you were on a 'Locked'
' ViewRep, but that doesn't work because for whatever reason, 
' If you're on the Master View Rep, it is ***NOT*** flagged 
' as being locked through the ActiveDesignViewRepresentation
' , even though it is locked if you were to look at the Design View
' directly through the Items collection.
'
' This might be another bug. 

If oRepManager.ActiveDesignViewRepresentation.Name <> "View1" Then
	Try 
		oRepManager.DesignViewRepresentations.Item("View1").Activate
	Catch 
		oRepManager.DesignViewRepresentations.Add("View1")
	Finally 
		oRepManager.DesignViewRepresentations.Item("View1").Activate
	End Try
End If

' Let's set our oViewRep to the Active Design View

Dim oViewRep As DesignViewRepresentation
oViewRep = oRepManager.ActiveDesignViewRepresentation

' Setting the DesignViewReps

Dim oViewReps As DesignViewRepresentations
oViewReps = oRepManager.DesignViewRepresentations

' Getting all of the Components from the assembly
    
Dim oCompOccs As ComponentOccurrences
oCompOccs = oCompDef.Occurrences

' Setting an empty ComponentOccurrence container

Dim oCompOcc As ComponentOccurrence

' Change the view of ALL Components to Invisible
' The Perspective / Camera error will only occure 
' if there are no visible Components. 

For Each oCompOcc In oCompOccs
    oCompOcc.Visible = False
Next

' Let's get the Camera from the Active View Rep

Dim oCam As Camera
oCam = ThisApplication.ActiveView.Camera


' If your set for Ortho, we'll change it to Perspective.
' If you're already set to Perspective, this doesn't 
' really do anything. 

oCam.Perspective = True
oCam.Apply

' NO matter, while on Perspective, and
' with no parts visible, once you change the -
' ViewOrientationType to any valid enum, the 
' PerspectiveAngle Is changed to a value outside
' of the Type Bounds For a Double.

oCam.ViewOrientationType = kIsoTopRightViewOrientation
oCam.Fit()
Call oCam.Apply()

' Typically doing the above will crash you, however
' occasionally it will not. Adding a new View Rep 
' 'which will change the active camera' will push it over
' the edge, but even sometimes this is just as spotty. 

Dim oNewViewRep As DesignViewRepresentation
oNewViewRep = oViewReps.Add("Crash")
oNewViewRep.Activate
oNewViewRep.Delete

Dim oOriginalCamera As Camera
oOriginalCamera = oViewRep.Camera

' Just in case you haven't crashed yet
' I'm throwing this in there because it where I will 
' absolutely run into problems. Trying to turn the Occurrences
' back to visible will make bad things happen!

For Each oCompOcc In oCompOccs
    oCompOcc.Visible = True
Next




 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 13 of 20

Anonymous
Not applicable

10759 is for TopRightViewOrientation but i need for FrontRightViewOrientation.

If you are saying to get programmatically using Camera object functionality. Then how to do so?

Please refer 2 images in my very first question for your reference.

So my question is 10759=TopRightViewOrientation= Horizontal and ?=FrontRightViewOrientation = Vertical

? is the Enum for view which i cant find.

0 Likes
Message 14 of 20

Anonymous
Not applicable

10759 is for TopRightViewOrientation but i need for FrontRightViewOrientation.

If you are saying to get programmatically using Camera object functionality. Then how to do so?

Please refer 2 images in my very first question for your reference.

So my question is 10759=TopRightViewOrientation= Horizontal and ?=FrontRightViewOrientation = Vertical

? is the Enum for view which i cant find.

0 Likes
Message 15 of 20

MegaJerk
Collaborator
Collaborator

Here is a complete list of the Inventor.ViewOrientationTypeEnum Enumerator

 



Public Enum ViewOrientationTypeEnum
  kDefaultViewOrientation = 10753
  kTopViewOrientation = 10754
  kRightViewOrientation = 10755
  kBackViewOrientation = 10756
  kBottomViewOrientation = 10757
  kLeftViewOrientation = 10758
  kIsoTopRightViewOrientation = 10759
  kIsoTopLeftViewOrientation = 10760
  kIsoBottomRightViewOrientation = 10761
  kIsoBottomLeftViewOrientation = 10762
  kArbitraryViewOrientation = 10763
  kFrontViewOrientation = 10764
  kCurrentViewOrientation = 10765
  kSavedCameraViewOrientation = 10766
  kFlatPivotRightViewOrientation = 10767
  kFlatPivotLeftViewOrientation = 10768
  kFlatPivot180ViewOrientation = 10769
  kFlatBacksideViewOrientation = 10770
  kFlatBacksidePivotRightViewOrientation = 10771
  kFlatBacksidePivotLeftViewOrientation = 10772
  kFlatBacksidePivot180ViewOrientation = 10773
End Enum

 

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 16 of 20

Anonymous
Not applicable

Enum below kFrontViewOrientation = 10764 are not working with me. It is showing error message as

"Error in rule: View Cube Rule, in document: Pressure Vessel AssemblyUpload.iam

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

 

and kDefaultViewOrientation = 10753 is also showing error.

 

Basically just I want to set this view  ISO view.PNG

0 Likes
Message 17 of 20

MegaJerk
Collaborator
Collaborator

Could you post the code that you are using apply these actions? 

It would be extremely helpful in evaluating your problem with more clarity. 




If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 18 of 20

Anonymous
Not applicable

Hi,

 

I know that this is an old thread but i want to share this to them who are figuring out how to get that particular view. The view is also known as "Home View" and can be set by pressing F6. Ilogic code for that is this simple and it's posted originally by MegaJerk:

 

SyntaxEditor Code Snippet

Call ThisApplication.ActiveView.GoHome

 

 -Mika

0 Likes
Message 19 of 20

S_May
Mentor
Mentor
Accepted solution

Hi @Anonymous,

 

This is not a code but that could help you synonymous AUTODESK APP

 

greetings

S_May

 

0 Likes
Message 20 of 20

S_May
Mentor
Mentor
Accepted solution

HI @Anonymous,

 

Zoom home & browser node rename & browser from a to z sort, helps you the code?

 

greetings

S_May

 
'-----start of ilogic-----
'sort components in the browser
ThisApplication.CommandManager.ControlDefinitions.Item _
("AssemblyBonusTools_AlphaSortComponentsCmd").Execute


'set a reference to the document
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument


'Set a reference to the top node of the active browser
Dim oTopNode As BrowserNode
oTopNode = oDoc.BrowserPanes.ActivePane.TopNode
Dim oNode As BrowserNode


For Each oNode In oTopNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = True Then
oNode.Expanded = False
End If
Next


'Return view to Home view
ThisApplication.CommandManager.ControlDefinitions.Item _
("AppViewCubeHomeCmd").Execute


'zoom all
ThisApplication.ActiveView.Fit
'-----end of ilogic-----
0 Likes