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