Monitor for left click event

Monitor for left click event

dylanTEV9W
Advocate Advocate
1,579 Views
19 Replies
Message 1 of 20

Monitor for left click event

dylanTEV9W
Advocate
Advocate

Hi All I'm trying to learn how to monitor for events from within Inventor. 

 

I'm running the following code which is modified from the cancel a double click API (link: example http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-A7B286A0-5234-49B0-8C89-00411A6B1173)

 

'Option Explicit is turned on above my imports at the start of my code. 

Private Sub Class_initializer()

OUIEvents = _invApp.CommandManager.UserInputEvents

End Sub

Private Sub OUIEvents_OnClick(ByVal SelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View, ByVal AdditionalInfo As NameValueMap, HandlingCode As HandlingCodeEnum)

If Button = 1 Then '1 is the Enum value for the left mouse button.

Debug.Print("Left click detected ")

End If

End Sub

 

 

Running the code doesn't cause the debug line to print though when i left click. Any help would be greatly appreciated!

0 Likes
Accepted solutions (1)
1,580 Views
19 Replies
Replies (19)
Message 2 of 20

bradeneuropeArthur
Mentor
Mentor

the on "clickevent" is not implemented:

but the "OnDoubleClick: is...:

Private Sub OUIEvents_OnDoubleClick(ByVal SelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View, ByVal AdditionalInfo As NameValueMap, HandlingCode As HandlingCodeEnum)
MsgBox ""
End Sub

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 20

dylanTEV9W
Advocate
Advocate

Thanks For Explaining that. I modified the code to the version below but I'm still not seeing anything happen. I know I must be missing something but I'm not sure what is?

 

Private WithEvents OUIEvents As UserInputEvents

Private Sub Class_initializer()

OUIEvents = _invApp.CommandManager.UserInputEvents

End Sub

Private Sub OUIEvents_OnDoubleClick(ByVal SelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View, ByVal AdditionalInfo As NameValueMap, HandlingCode As HandlingCodeEnum)

MsgBox("")

Debug.Print("")

End Sub

 

 

0 Likes
Message 4 of 20

bradeneuropeArthur
Mentor
Mentor

What are you using vba; vb.net; or ilogic

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 20

dylanTEV9W
Advocate
Advocate

I'm using VB.Net.

0 Likes
Message 6 of 20

bradeneuropeArthur
Mentor
Mentor

within an add in or standalone app?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 20

dylanTEV9W
Advocate
Advocate

As a standalone application.

0 Likes
Message 8 of 20

bradeneuropeArthur
Mentor
Mentor

did you create a separate class for the events?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 9 of 20

dylanTEV9W
Advocate
Advocate

No I was trying to run it out of my base application class. Will I need a seperate class to handle events?

0 Likes
Message 10 of 20

bradeneuropeArthur
Mentor
Mentor

better yes, but if it is in a class already it must work too.

 

please keep reading.

 

put this in your class:

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 11 of 20

bradeneuropeArthur
Mentor
Mentor

in your class:

Public ThisApplicationa As Inventor.Application
Public WithEvents OUIEvents As UserInputEvents
Public WithEvents inev As ApplicationEvents
Public Sub Activate()
Set ThisApplicationa = ThisApplication
OUIEvents = ThisApplicationa.CommandManager.UserInputEvents
MsgBox ThisApplicationa.ActiveDocument.FullDocumentName
End Sub
Private Sub OUIEvents_OnClick(ByVal SelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View, ByVal AdditionalInfo As NameValueMap, HandlingCode As HandlingCodeEnum)
If Button = 1 Then '1 is the Enum value for the left mouse button.
Debug.Print ("Left click detected ")
End If
End Sub

Private Sub Class_Initialize()
MsgBox "ini"
End Sub

Public Sub OUIEvents_OnActivateCommand(ByVal CommandName As String, ByVal Context As NameValueMap)
MsgBox CommandName
End Sub

Public Sub OUIEvents_OnDoubleClick(ByVal SelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View, ByVal AdditionalInfo As NameValueMap, HandlingCode As HandlingCodeEnum)
MsgBox "clil=ck"
End Sub

keep reading....

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 12 of 20

bradeneuropeArthur
Mentor
Mentor

and this this in your program like userform or else

 

Dim a  As New Class1
Public Sub main()

Set a = New Class1
a.Activate

End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 13 of 20

dylanTEV9W
Advocate
Advocate

Okay I will try running your code right now. Thank you for all of your help so far!

0 Likes
Message 14 of 20

bradeneuropeArthur
Mentor
Mentor

maybe you need to change this:

 

Public Sub Activate()
Set ThisApplicationa = ThisApplication
' To this depening of your app
Public Sub Activate()
Set ThisApplicationa = getobject("inventor.application")

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 15 of 20

bradeneuropeArthur
Mentor
Mentor

or second you could use:

 

Dim a  As Class1
Public Sub main()

Set a = New Class1
Dim x As Application
Set x = GetObject("inventor.application")
Call a.Activate(x)

End Sub

and this in your class:

Public Sub Activate(ThisApplication As Inventor.Application)

Set OUIEvents = ThisApplicationa.CommandManager.UserInputEvents
……………………………………….

Hope it works with your app to.

For me it works...

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 16 of 20

dylanTEV9W
Advocate
Advocate

I'm converting from vba to vb.net so I can run it in my application. I will post if I'm successful along with the converted code.

0 Likes
Message 17 of 20

bradeneuropeArthur
Mentor
Mentor

Good job to convert it to vb.net.....

I have this code provided also ready for vba. If you need I can provide it too.

Let me know if you need help.

At the moment I am far from my desk.

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 18 of 20

dylanTEV9W
Advocate
Advocate

I think I'm still missing something here. I'm still very unclear on what needs to happen for my app. to constantly be watching for and respond to events within Inventor. I'm able to make Activate() run within my application but only by triggering it within another event. But I'm not sure what I need to make my application constantly look for the click event? This is what I have so far but it doesn't seem to detect left click events from inventor. 

 

 

lass Class1

Public ThisApplicationa As Inventor.Application

Public WithEvents OUIEvents As UserInputEvents

Public WithEvents Inev As ApplicationEvents

Public Event XEvent()


Public Sub Activate()

ThisApplicationa = Marshal.GetActiveObject("Inventor.Application")

OUIEvents = ThisApplicationa.CommandManager.UserInputEvents

'MsgBox(ThisApplicationa.ActiveDocument.FullDocumentName)

End Sub

Public Sub OUIEvents_OnClick(ByVal SelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View, ByVal AdditionalInfo As NameValueMap, HandlingCode As HandlingCodeEnum)

If Button = 1 Then '1 is the Enum value for the left mouse button.

RaiseEvent XEvent()

End If

End Sub

Private Sub Class_Initialize()

MsgBox("ini")

End Sub

Public Sub OUIEvents_OnActivateCommand(ByVal CommandName As String, ByVal Context As NameValueMap)

MsgBox(CommandName)

End Sub

Public Sub OUIEvents_OnDoubleClick(ByVal SelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View, ByVal AdditionalInfo As NameValueMap, HandlingCode As HandlingCodeEnum)

MsgBox("clil=ck")

End Sub

End Class

Public Class Form1

 

Dim WithEvents cls1 As Class1 = New Class1()

 

Private Sub ABC() Handles cls1.XEvent

 

MsgBox("Click Recieved")

 

End Sub

 

Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Object) Handles Me.Activated

 

cls1.Activate()

 

End Sub

 

End Class

 

0 Likes
Message 19 of 20

dylanTEV9W
Advocate
Advocate

Okay so I did some more revision on my code. I'm currently able to detect and react to events from the UserInputEvents class but not the mouse events class. This is an issue for me since I'm trying to only detect a single click in Inventor with my code. Right now when I try to monitor for an event from the MouseEvents class nothing happens. This is what I have coded so far. Any more help that can be offered would be greatly appreciated!

 

Class EventClass

'Public class members

Public _invApp As Inventor.Application 'Get inventor application

Public WithEvents User_input_events As UserInputEvents 'Create a public member with events for the inventor UserInputEvents

Public WithEvents App_events As ApplicationEvents 'Create a public member with events for the inventor ApplicationEvents

Public WithEvents Mouse_events As MouseEvents

Public WithEvents Interaction_events As InteractionEvents


'Public sub routines

Public Sub Activate() 'Activates the event class and assigns objects to the ThisApplication and user_input_events members.

_invApp = Marshal.GetActiveObject("Inventor.Application") 'Assigns the inventor application.

User_input_events = _invApp.CommandManager.UserInputEvents 'Assign the user input events.

Interaction_events = _invApp.CommandManager.CreateInteractionEvents

Mouse_events = Interaction_events.MouseEvents

Mouse_events.MouseMoveEnabled = True 'Enable the ability to fire mouse move events.

End Sub

'Private sub routines

Private Sub OnLeftClick() Handles Mouse_events.OnMouseClick 'Private sub fires when the mouse is clicked in the active inventor doc.

Debug.Print("A mouse button was clicked")

End Sub

Private Sub User_input_events_OnDrag(DragState As DragStateEnum, ShiftKeys As ShiftStateEnum, ModelPosition As Point, ViewPosition As Point2d, View As View, AdditionalInfo As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles User_input_events.OnDrag 'Private sub fires when something in the active inventor doc is selected.

Dim select_set As SelectSet = _invApp.ActiveDocument.SelectSet 'Define a select set member.

Dim selected_face As Face 'Define a face member

If select_set.Item(1).Type = ObjectTypeEnum.kFaceObject Then

'Debug.Print("looks like you're trying to drag a face")

selected_face = select_set.Item(1)

Debug.Print(ViewPosition.X)

Debug.Print(ViewPosition.Y)

End If

End Sub

Private Sub Mouse_events_OnMouseMove(Button As MouseButtonEnum, ShiftKeys As ShiftStateEnum, ModelPosition As Point, ViewPosition As Point2d, View As View) Handles Mouse_events.OnMouseMove

Debug.Print("hi")

'Debug.Print(Button)

End Sub

End Class

 

0 Likes
Message 20 of 20

dylanTEV9W
Advocate
Advocate
Accepted solution

So when I was combing through the On Drag example code I found the solution I wasn't telling the interaction_events to start. Here is the completed code. Note that once the user hits escape the interaction events deactivate and stop looking for clicks. If you're trying to do something similar to this and are confused and having trouble like I was hopefully this will provide some answers on how to do this with VB.Net.

 

Class EventClass

'Public class members

Public _invApp As Inventor.Application 'Get inventor application

Public WithEvents User_input_events As UserInputEvents 'Create a public member with events for the inventor UserInputEvents

Public WithEvents App_events As ApplicationEvents 'Create a public member with events for the inventor ApplicationEvents

Public WithEvents Mouse_events As MouseEvents

Public WithEvents Interaction_events As InteractionEvents


'Public sub routines

Public Sub Activate() 'Activates the event class and assigns objects to the ThisApplication and user_input_events members.

_invApp = Marshal.GetActiveObject("Inventor.Application") 'Assigns the inventor application.

User_input_events = _invApp.CommandManager.UserInputEvents 'Assign the user input events.

Interaction_events = _invApp.CommandManager.CreateInteractionEvents 'Create the interaction events object.

Mouse_events = Interaction_events.MouseEvents 'Assign the mouse events.

Mouse_events.MouseMoveEnabled = True 'Enable the ability to fire mouse move events.

Interaction_events.Start() 'Activates the interaction events so that they can be passed to this app.

End Sub

'Private sub routines

Private Sub User_input_events_OnDrag(DragState As DragStateEnum, ShiftKeys As ShiftStateEnum, ModelPosition As Point, ViewPosition As Point2d, View As View, AdditionalInfo As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles User_input_events.OnDrag 'Private sub fires when something in the active inventor doc is selected.

Dim select_set As SelectSet = _invApp.ActiveDocument.SelectSet 'Define a select set member.

Dim selected_face As Face 'Define a face member

If select_set.Item(1).Type = ObjectTypeEnum.kFaceObject Then

'Debug.Print("looks like you're trying to drag a face")

selected_face = select_set.Item(1)

Debug.Print(ViewPosition.X)

Debug.Print(ViewPosition.Y)

End If

End Sub

Private Sub Mouse_events_OnMouseClick(Button As MouseButtonEnum, ShiftKeys As ShiftStateEnum, ModelPosition As Point, ViewPosition As Point2d, View As View) Handles Mouse_events.OnMouseClick

If Button = MouseButtonEnum.kLeftMouseButton Then

Debug.Print("The left Mouse button was clicked.")

End If

End Sub

'Private Sub OnClick() Handles app_events.

End Class