Ilogic rule to set ViewCube

Ilogic rule to set ViewCube

ch_giacomo
Enthusiast Enthusiast
1,363 Views
9 Replies
Message 1 of 10

Ilogic rule to set ViewCube

ch_giacomo
Enthusiast
Enthusiast

Hi all, given that I understand little about ilogic, but I managed to make this rule that sets the front view of the IPT or IAM (function on both) and then does a rotation in the desired ViewCube direction (changing the reference number) and set Home view.

So far everything is perfect and I save a lot of clicks

I wanted to ask for help, I would like to implement the choice of the Front view with a mouse click on a face, let me explain better:

now it works like this:
I open the file, position the view as I want and start the rule that sets the Font view and then the Home

The function I can't do is:
After opening the file, start the rule which should ask me to click on a face of the piece and then the rule does the rest

Rule:

 

'Set ViewCube view to Front
Dim name1 As String = "AppViewCubeViewFrontCmd"
Dim oDef1 As ButtonDefinition = ThisApplication.CommandManager _
         .ControlDefinitions.Item(name1)
oDef1.Execute

Dim oCamera As Camera
'Rotation of the ViewCube
oCamera = ThisApplication.ActiveView.Camera
oCamera.ViewOrientationType = 10759 'IsoTopRight
oCamera.Apply

'Set ViewCube view to Home
Dim name2 As String = "AppViewCubeViewHomeFloatingCmd"
Dim oDef2 As ButtonDefinition = ThisApplication.CommandManager _
         .ControlDefinitions.Item(name2)
oDef2.Execute

'zoom in
ThisApplication.ActiveView.Fit


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

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

'Go to Home
'Call ThisApplication.ActiveView.GoHome
0 Likes
Accepted solutions (2)
1,364 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Hi @ch_giacomo.  I just threw something together along the lines of your idea that you can take a look at.  It lets you pick a planar face, then uses its 'Normal' (a UnitVector) to set the direction of the view to look at that face.  However, this does not take rotation of the model into account yet.  Then it fits the model in view, and sets front view.  Then uses ViewOrientation based on that new orientation understanding to move to top right ISO orientation, fits again, then sets that as home.  I have not tested this yet though, because I do not have any use for it.

 

ThisApplication.UserInterfaceManager.ShowViewCube = True
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a Flat Face.")
If oObj Is Nothing OrElse (TypeOf oObj Is Inventor.Face = False) Then Exit Sub
Dim oFace As Inventor.Face = oObj
Dim oView As Inventor.View = ThisApplication.ActiveView
Dim oPlane As Inventor.Plane = oFace.Geometry
'sets view direction, but not necessarily rotation
'could also set 'Target' & 'Eye' of the camera to do this
oView.Camera.UpVector = oPlane.Normal
oView.Camera.Fit
oView.Camera.Apply
oView.Fit
oView.SetCurrentAsFront
oView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation
oView.Camera.Fit
oView.Camera.Apply
oView.Fit
oView.SetCurrentAsHome(True)

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

ch_giacomo
Enthusiast
Enthusiast

Thanks. unfortunately it doesn't work, it asks me to select the face but then it sets the front view without adapting to the rotation of the selected face

0 Likes
Message 4 of 10

ch_giacomo
Enthusiast
Enthusiast

Maybe I explained myself wrong.
The face to select should become the front view
Thank you

0 Likes
Message 5 of 10

WCrihfield
Mentor
Mentor
Accepted solution

I'm just a bit rusty on manipulating the view's camera, because I pretty much never need to do that by code for any of my own automation solutions/projects.  It does seem much simpler to just use the commands in this case, but I usually to not like executing commands from code, so I was trying to avoid it by using API somehow instead.  Below is a much simpler rule that uses the commands instead.  Setting the front view the way you want it is easy.  Its the second step that is more difficult to achieve.  I'm still working on continuing the code to reorient itself to where the new 'home' is the top-right iso view, after the front has been set, but it keeps wanting to go back to the previous orientation of where home was.  It's almost like some sort of update or refresh needs to happen between setting front, and setting the new top right ISO from that perspective.

ThisApplication.UserInterfaceManager.ShowViewCube = True
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a Flat Face.")
If oObj Is Nothing OrElse (TypeOf oObj Is Inventor.Face = False) Then Exit Sub
Dim oFace As Inventor.Face = oObj
ThisDoc.Document.SelectSet.Clear
ThisDoc.Document.SelectSet.Select(oFace)
Dim oCDs As ControlDefinitions = ThisApplication.CommandManager.ControlDefinitions
oCDs.Item("AppLookAtCmd").Execute2(True)
oCDs.Item("AppZoomAllCmd").Execute2(True)
'oCDs.Item("AppViewCubeViewFrontCmd").Execute2(True)
ThisApplication.ActiveView.SetCurrentAsFront

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 10

ch_giacomo
Enthusiast
Enthusiast

Perfect, you solved my problem, thank you very much.
For the second part I copied from the rule I wrote in the previous post and everything works.

Surely you can do better, but to my knowledge for now it's okay.

Here is the complete rule for my functional needs:

 

ThisApplication.UserInterfaceManager.ShowViewCube = True
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a Flat Face.")
If oObj Is Nothing OrElse (TypeOf oObj Is Inventor.Face = False) Then Exit Sub
Dim oFace As Inventor.Face = oObj
ThisDoc.Document.SelectSet.Clear
ThisDoc.Document.SelectSet.Select(oFace)
Dim oCDs As ControlDefinitions = ThisApplication.CommandManager.ControlDefinitions
oCDs.Item("AppLookAtCmd").Execute2(True)
oCDs.Item("AppZoomAllCmd").Execute2(True)
'oCDs.Item("AppViewCubeViewFrontCmd").Execute2(True)
ThisApplication.ActiveView.SetCurrentAsFront

Dim oCamera As Camera
'Rotazione del ViewCube
oCamera = ThisApplication.ActiveView.Camera 
oCamera.ViewOrientationType = 10759 'IsoTopRight
oCamera.Apply

'Settare vista ViewCube su Home
Dim name2 As String = "AppViewCubeViewHomeFloatingCmd"
Dim oDef2 As ButtonDefinition = ThisApplication.CommandManager _
		.ControlDefinitions.Item(name2)
oDef2.Execute

'zoom all
ThisApplication.ActiveView.Fit


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

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

'Go to Home
'Call ThisApplication.ActiveView.GoHome	

 

Message 7 of 10

WCrihfield
Mentor
Mentor

Thank you too.  I got a refresher course in this stuff today, and I like to keep learning every day.  It turned out to be simpler than I was thinking...except for the 'LookAt' part.  So, I kept that one command, then used API for the rest, then condensed it.  Below is what I'm planning on storing away as a custom snippet & external rule.

 

ThisApplication.UserInterfaceManager.ShowViewCube = True
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a Flat Face.")
If oObj Is Nothing OrElse (TypeOf oObj Is Inventor.Face = False) Then Exit Sub
Dim oFace As Inventor.Face = oObj
Dim oView As Inventor.View = ThisApplication.ActiveView
Dim oDoc As Document = oView.Document : oDoc.SelectSet.Clear : oDoc.SelectSet.Select(oFace)
ThisApplication.CommandManager.ControlDefinitions.Item("AppLookAtCmd").Execute2(True)
oView.SetCurrentAsFront
Dim oCamera As Camera = oView.Camera
oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation
oCamera.Fit : oCamera.Apply : oView.Fit
oView.SetCurrentAsHome(True)

Edit:  By the way, we could shorten this even further if we wanted to 'pre-select' the face before running the rule.  Then we could just get that Face from the first object in the Document.SelectSet, without needing the Pick function in there.  Just another thought.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 10

ch_giacomo
Enthusiast
Enthusiast

tomorrow in the office I will also try this solution.

For the pre-selection of the face convenient in the .IPT but in the .IAM the pre-selection of the face is not very convenient "for my activities".

Thank you for the time you dedicated to me.

0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Here is something you can play around with tomorrow then.  This combines both.  If you pre-select the face, it will use that.  If you did not pre-select the face, it will go ahead and prompt you to pick one.  This is a pretty good strategy to build into most utility tools, because it becomes more dynamic, and more like the built-in user interface tools/commands, if you don't mind the code being a little longer.  And lets face it, that code is going to be hidden 99.9% of the time anyways, so as long as it works as expected, that's what really matters anyways.  Condensing is just personal style/preference, and can sometimes make code harder to read/follow later, if others inherit it.

ThisApplication.UserInterfaceManager.ShowViewCube = True
Dim oView As Inventor.View = ThisApplication.ActiveView
Dim oDoc As Document = oView.Document
Dim oFace As Inventor.Face = Nothing
Dim oSS As SelectSet = oDoc.SelectSet
If oSS.Count > 0 Then
	For Each oItem In oSS
		If TypeOf oItem Is Face Then
			oFace = oItem
			Exit For 'exit the loop, while keeping the current value of oFace
		End If
	Next
	If IsNothing(oFace) Then oSS.Clear
End If
If oSS.Count = 0 Or oFace Is Nothing Then 'it was not pre-selected, so Pick it now
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a Flat Face.")
	If oObj Is Nothing OrElse (TypeOf oObj Is Inventor.Face = False) Then Exit Sub
	oFace = oObj : oSS.Clear : oSS.Select(oFace)
End If
ThisApplication.CommandManager.ControlDefinitions.Item("AppLookAtCmd").Execute2(True)
oView.SetCurrentAsFront
Dim oCamera As Camera = oView.Camera
oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation
oCamera.Fit : oCamera.Apply : oView.Fit
oView.SetCurrentAsHome(True)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 10

ch_giacomo
Enthusiast
Enthusiast
excellent solution just tested, works great.
Thank you
0 Likes