Set Pivot point to center screen

Set Pivot point to center screen

cnoJTCG6
Contributor Contributor
2,036 Views
13 Replies
Message 1 of 14

Set Pivot point to center screen

cnoJTCG6
Contributor
Contributor

Hello,

 

Is there a way to programmatically set the pivot point to the center of the screen when there is no movement for a certain time?

 

I remain slightly dissatisfied with the pivot point orientation in the 3D environment, I use a 3D Connexion Mouse.
The reset of the pivot looks not consistent and I can't quite figure out what the trigger is or could be.
Especially with slim parts it can be very annoying.
The combination of a pressed F4 button and left mouse click on a model surface seems to work best to reset the pivot point.
And sometimes it also looks like a selected vertex is doing something.

If I'm not missing any settings or options, there's room for improvement.

 

For example, is it possible to access the pivot point through code?
Or is it possible to combine a F4 button action together with a mouse click?

 

 

0 Likes
2,037 Views
13 Replies
Replies (13)
Message 2 of 14

WCrihfield
Mentor
Mentor

Hi @cnoJTCG6.  This can sometimes be awkward to deal with or get used to.  Here are some other posts on the same or similar subject:

https://help.autodesk.com/view/INVNTOR/2021/ENU/?caas=caas/discussion/t5/Inventor-Forum/Is-there-any... 

https://help.autodesk.com/view/INVNTOR/2021/ENU/?caas=caas/discussion/t5/Inventor-Forum/Rotate-on-an... 

And here is a link to an online help page where it shows you the 'Center' tool within the 'SteeringWheel' tool, which has a similar function.

https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=GUID-5D371AC3-EBC4-4B8D-9A9B-4B9B2B290D8B

 

I too have a 3DConnexion SpaceMousePro which I've been using for years now, and love it.  After using one of these for a while and getting it all set-up the way you like it, you don't ever want to go back to not having one.😁  However, the one I've got has a lot of settings, and when I try to use a co-worker's 3D mouse, which is set-up differently, it's so awkward I'd rather do without and use the manual methods.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 14

checkcheck_master
Advocate
Advocate

Thanks  for your response and tips.

 

See code, that's pretty much what I was thinking about.
Now it is only the case that a key or button has to be used to activate the code, I now put it under a button on the 3D Connexion mouse, see attached video.
That should be smarter.
Not hindered by knowledge:
Is it possible to have an iLogic rule running in the background who is listening to a, lets say, 'one(1) second left mouse button down' action and on that triggers the attached code.
As far as I can see nothing else happens when you hold down the left mouse button for a longer period of time, hence the idea.
To what extent can a macro/rule run in the background?
In my opinion, for example, a UserForm can be configured in such a way that it can interact with the program from which it is started.
Is that possible for Inventor in this way?
You don't know what you don't know, am I missing something?

 

 

 

Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Public Sub Set_Pivot_Point()

    Dim oCommandMgr As CommandManager
    Set oCommandMgr = ThisApplication.CommandManager
    
    Dim oControlDef As ControlDefinition
    Set oControlDef = oCommandMgr.ControlDefinitions.item("AppSetPivotPointCmd")

    Call oControlDef.Execute
    
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
        
End Sub

 

 

 

0 Likes
Message 4 of 14

WCrihfield
Mentor
Mentor

Hi @checkcheck_master.  I'm familiar with the command, but not the first Sub you used.  Yes, I believe it would be possible to have an iLogic rule running in the background, listening for the mouse button down event, but I'm not sure how to configure any specific 'wait time' for the mouse button to be down before triggering the event.  There are some pre-defined Events under the InteractionEvents.MouseEvents object, one of which is called OnMouseDown, which I believe will give you the functionality you are looking for.  I have created event handler codes using MouseEvents before, but I believe I used the OnMouseClick event for those.  If you're not familiar with the process, here is a link to my contribution post about creating event handlers using an iLogic rule.

The code below is a fairly simple example using the OnMouseClick event to report mouse position.  It is designed as a one shot use, due to how/when it is disposed of.

Sub Main
	Dim oIntEv As InteractionEvents = ThisApplication.CommandManager.CreateInteractionEvents
	Dim oMouseEv As MouseEvents = oIntEv.MouseEvents
	AddHandler oMouseEv.OnMouseClick  ,AddressOf oMouseEv_OnMouseClick 
	oIntEv.Start
End Sub

Sub oMouseEv_OnMouseClick(oMBtn As MouseButtonEnum, oShiftState As ShiftStateEnum, oMPos As Inventor.Point, oViewPos As Point2d, oView As Inventor.View)
   MsgBox("Model Position = " & oMPos.X & " cm x " & oMPos.Y & " cm (from model origin)" & vbCrLf & _
  "View Position = " & oViewPos.X & " x " & oViewPos.Y & " (from top left corner of view)", , "MOUSE POSITION")
   
	'now to dispose of the event handler
	Dim oIntEv As InteractionEvents = ThisApplication.CommandManager.CreateInteractionEvents
	Dim oMouseEv As MouseEvents = oIntEv.MouseEvents
	RemoveHandler oMouseEv.OnMouseClick, AddressOf oMouseEv_OnMouseClick
	'MsgBox("Just removed the OnMouseClick event handler.",,"")
End Sub

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 14

checkcheck_master
Advocate
Advocate

Thank you again.
That's a tough topic for me, I'm going to dig into it and see how far I get.

 

In the meantime, if there are fellow combatants with experience in this area, I would be most welcome.

0 Likes
Message 6 of 14

Ralf_Krieg
Advisor
Advisor

Hello

 

You can use the OnMouseDown event to start a timer. If the you release the mouse button within the interval, the OnMouseUp event stops the timer and nothing more happen. If the interval has reached it's end before the OnMouseUp event raises, an OnTimedEvent is fired and within the OnTimedEvent sub you can run your code. See Code below.

Before you take a lot of time to implement this, be aware of the limitations. The interaction started by this rule is terminated every time another command is started or if you change the environment (e.g. start sketch edit, activate another view window). You need to restart it always after command has finished and in a new environment. Within the started command, e.g. the extrusion command, the long mouse click is not useable.

If you run the the rule, pressing Escape also removes the the event handlers by canceling the interaction.

 

Imports System.Timers
Class ThisRule
	
	Private aTimer As System.Timers.Timer
	Private oUIEv As UserInterfaceEvents
	Private oIntEv As InteractionEvents
	Private oMouseEv As MouseEvents
	
Sub Main
	oUIEv = ThisApplication.UserInterfaceManager.UserInterfaceEvents 
	oIntEv = ThisApplication.CommandManager.CreateInteractionEvents
	oMouseEv = oIntEv.MouseEvents
	
	AddHandler oMouseEv.OnMouseDown, AddressOf oMouseEv_OnMouseDown
	AddHandler oMouseEv.OnMouseUp, AddressOf oMouseEv_OnMouseUp
	AddHandler oUIEv.Onenvironmentchange, AddressOf oUIEv_OnEnvironmentChange
	AddHandler oIntEv.OnTerminate, AddressOf oIntEv_OnTerminate
		
	oIntEv.Start
End Sub

Sub oIntEv_OnTerminate()
	RemoveHandler oMouseEv.OnMouseDown, AddressOf oMouseEv_OnMouseDown
	RemoveHandler oMouseEv.OnMouseUp, AddressOf oMouseEv_OnMouseUp
	RemoveHandler oUIEv.Onenvironmentchange, AddressOf oUIEv_OnEnvironmentChange
	MsgBox("event handlers removed")
End Sub

Sub oMouseEv_OnMouseDown(Button As MouseButtonEnum, ShiftKeys As ShiftStateEnum, ModelPosition As Point, ViewPosition As Point2d, View As View) 
	If Button=MouseButtonEnum.kLeftMouseButton Then
		SetTimer()
	End If
End Sub
    
Sub oMouseEv_OnMouseUp(Button As MouseButtonEnum, ShiftKeys As ShiftStateEnum, ModelPosition As Point, ViewPosition As Point2d, View As View) 
	If Button=MouseButtonEnum.kLeftMouseButton Then
		aTimer.Stop()
	    aTimer.Dispose()
	End If
End Sub

Sub oUIEv_OnEnvironmentChange(oEnv As Inventor.Environment, oEnvState As EnvironmentStateEnum, oBeforeOrAfter As EventTimingEnum, oContext As NameValueMap, ByRef oHandlingCode As HandlingCodeEnum)
	If oBeforeOrAfter = kbefore Then
		oIntEv.Stop
	End If
End Sub

Private Sub SetTimer()
    aTimer = New System.Timers.Timer(500)
    AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
    aTimer.AutoReset = False
    aTimer.Enabled = True
End Sub

Private Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
    MsgBox("Long Click")
End Sub 
	
End Class

 

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 7 of 14

cnoJTCG6
Contributor
Contributor

Thank you Krieg for your response.
Very educational, that's for sure.

Thanks for pointing out its limitations, I didn't know.
The plus sign appears in your code, which in my opinion means that other functionality no longer works.
I was hoping for something to run in the background while everything else 'just' works.
See the code below which, as far as I can tell, actually runs in the background and tells you when a constraint has been applied.
Not hindered by knowledge, can this be converted to a mouse event?
Also from this code I find that it stops as soon as the environment is switched.

 

Option Explicit on

Sub Main
Dim evtListener As New MateListener(ThisServer, Parameter)
evtListener = Nothing
End Sub

Public Class MateListener

Private WithEvents m_AsmEvts As Inventor.AssemblyEvents = Nothing

Private Parameter As Object

Sub New(invServer As InventorServer, Parameter As Object)
m_AsmEvts = invServer.AssemblyEvents
Me.Parameter = Parameter
End Sub

Private Sub m_AsmEvts_OnNewRelation(ByVal DocumentObject As Inventor._AssemblyDocument, ByVal Relationship As Object, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_AsmEvts.OnNewRelationship
If BeforeOrAfter = Inventor.EventTimingEnum.kAfter Then
MsgBox("New relationship:" & vbTab & Relationship.Name)
m_AsmEvts = Nothing
End If
End Sub

End Class

0 Likes
Message 8 of 14

WCrihfield
Mentor
Mentor

Hi @cnoJTCG6.  Each type of event handler code defined with Inventor's API that is exposed for us to access has its own properties, qualities, and quirks.  Some may even require you to be in a certain mode or environment before they will work.  This is the case for the MouseEvents object, because you can only access the MouseEvents object under the TransactionEvents object, as one of its properties.  There are several other types of events that are also located under the TransactionEvents (KeyboardEvents, ManipulatorEvents, MeasureEvents, SelectEvents, & TriadEvents).  Therefore all those events located under a TransactionEvents object can only be monitored/listened for while the TransactionEvents object is active (between Start and Stop/Exit).  This is just nature of this specific set of event handling codes that are defined within the Inventor API for us to be able to use.  There are other general vb.net ways of dealing with mouse events, but mostly they are dealing with Windows Forms or a Control within another application in some way.

 

In any event, even if you wanted to leave some sort of event handler running in the background that would listen for something specific to happen, then when that event happens, create another specific type of event handler for another purpose, I believe that that type of behavior would be best designed/created as an Inventor Add-in, instead of an iLogic rule or VBA macro.  However, I haven't had much experience with creating add-ins yet, due to corporate/ company wide restrictions, which won't allow any employees to have administrator rights on their own computers.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 14

checkcheck_master
Advocate
Advocate

Thank you WCrihfield for your comprehensive explanation.
I also have no experience with Inventor and writing an Add-in.
I'm still hoping for some brilliant idea.
The principle and behavior of the code as suggested with regard to placing a constraint goes a long way in the right direction.
Now I have assigned a button on my 3D mouse that invites you to choose a Pivot Point, that works fine in principle, but it could be better.
That we still have to waste words on this, it should of course have been eliminated by Autodesk long ago, but that's aside.
Anyway, as said, if the MateListener can become a MouseListener...

0 Likes
Message 10 of 14

WCrihfield
Mentor
Mentor

Sorry for babbling on, but the short answer to your earlier question, if the MateListener can become a MouseListener, is no.  The event handler being used in the code you posted is another one that is already defined within the Inventor API, called AssemblyEvents.OnNewRelationship.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 14

checkcheck_master
Advocate
Advocate

Thank you for your patience and explaining it to me again. I really appreciate.
You notice that sometimes it is difficult for me to comprehend it.
In my simplicity I think if you can check when a constraint is being applied it shouldn't be that complicated to detect a mouse click by something running in the background.
You refer/assumes that in that case an add-in would be more appropriate.
It still has to sink in for a while.

0 Likes
Message 12 of 14

Kaplar.Balazs
Contributor
Contributor

Hi,

 

Another option for pivot point selection would be to set a command on your 3DConnexion device using the Radial Menus on the 2 side buttons and one node is programmed to "Pivot" command from the command list. This does exactly the same as F4+left click but without having to move over your hand from the 3D mouse.


I'm also having a hard time understanding the pan/zoom limits of the 3D mouse especially with Perspective projection. However, reaching the end of zoom then waiting approx 2,5 seconds resets the pivot of the mouse. I got used to it, others don't.

0 Likes
Message 13 of 14

checkcheck_master
Advocate
Advocate

Thank Kaplar.Balazs for your response.

That is indeed what I do now, in addition I have tried to program a mouse click after it but that is still a bit unstable...

 

Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Declare PtrSafe Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_KEYUP = &H101

Public Sub Set_Pivot_Point()

    Dim oCommandMgr As CommandManager
    Set oCommandMgr = ThisApplication.CommandManager
    
    Dim oControlDef As ControlDefinition
    Set oControlDef = oCommandMgr.ControlDefinitions.item("AppSetPivotPointCmd")

    Call oControlDef.Execute
    
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
            
End Sub
0 Likes
Message 14 of 14

checkcheck_master
Advocate
Advocate

Earlier I wrote about VBA code that I posted 'but that is still a bit unstable'.

Since then I do this using an iLogic rule that is called from VBA so that I can still have it under a button on my 3D Connexion mouse.
Works well so far with no crashes.
The escape key sometimes doesn't get through, but it can be overcome.
You must be with the mouse cursor on the model when you press the button, then this location is moved to the center of the screen and raised as a Pivot point.

 

See video attached.

 

Below the iLogic code followed by the VBA code to call the iLogic rule, make sure you set the path name to the macro correctly.

 

Public Class One

Private Declare Sub mouse_event Lib "user32"(ByVal dwFlags As Integer, _
      ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, _
      ByVal dwExtraInfo As Integer)

Sub Main
	
    Try
		Dim oCommandMgr As CommandManager
	    oCommandMgr = ThisApplication.CommandManager
	    
	    Dim oControlDef As ControlDefinition
	    oControlDef = oCommandMgr.ControlDefinitions.Item("AppSetPivotPointCmd")

	    Call oControlDef.Execute
		
		Call ThisApplication.UserInterfaceManager.DoEvents
		mouse_event(&H2, 0, 0, 0, 0)
		Call ThisApplication.UserInterfaceManager.DoEvents
	    mouse_event(&H4, 0, 0, 0, 0)
		Call ThisApplication.UserInterfaceManager.DoEvents
				
		' For Help
		'MOUSEEVENTF_MOVE = &H1
		'MOUSEEVENTF_LEFTDOWN = &H2
		'MOUSEEVENTF_LEFTUP = &H4
		'MOUSEEVENTF_RIGHTDOWN = &H8
		'MOUSEEVENTF_RIGHTUP = &H10
				
		' Send ESC-key to the system
		System.Windows.Forms.SendKeys.SendWait("+{ESCAPE}")
				
	Catch
	End Try
         		
End Sub

End Class

 

 

 

Public Sub Set_Pivot_Point()
'From https://www.cadlinecommunity.co.uk/hc/en-us/articles/115000859309
Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns
Set addIns = ThisApplication.ApplicationAddIns
    For Each addIn In addIns
        If InStr(addIn.DisplayName, "iLogic") > 0 Then
                        addIn.Activate
            Dim iLogicAuto As Object
            Set iLogicAuto = addIn.Automation
            Exit For
        End If
    Next
  
Dim INTERNALrule As String
INTERNALrule = "Rule0"

Dim EXTERNALrule As String
EXTERNALrule = "C:\Workingfolder\CAD Settings\Inventor\Macros\Set_Pivot_Point.iLogicVb"
 
  Dim oDoc As Document
 
  Set oDoc = ThisApplication.ActiveDocument
  If oDoc Is Nothing Then
    MsgBox "Missing Inventor Document"
    Exit Sub
  End If
 
'iLogicAuto.RunRule oDoc, INTERNALrule 'for internal rule
iLogicAuto.RunExternalRule oDoc, EXTERNALrule 'for external rule

End Sub

 

 

 

0 Likes