Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Michael.Navara
in reply to: wannensn

You can handle OnDoubleClick event from UserInputEvents. This is a small example how to do it in iLogic. Main code is in class SketchedSymbolDoubleClickHandler. Usage of SharedVariable is necessary to keep the handler alive between rule edits. 

 

 

 

    Sub Main()
        Dim doubleClickHandler As SketchedSymbolDoubleClickHandler
        Dim name = "DoubleClickHandler"
        If SharedVariable.Exists(name) Then
            doubleClickHandler = SharedVariable.Value(name)
        Else
            doubleClickHandler = New SketchedSymbolDoubleClickHandler(ThisApplication)
            SharedVariable.Value(name) = doubleClickHandler
        End If

        If doubleClickHandler.IsActive Then
            doubleClickHandler.StopHandling()
        Else
            doubleClickHandler.StartHandling()
        End If

    End Sub



    Class SketchedSymbolDoubleClickHandler
        Implements IDisposable

        Private ReadOnly inventor As Application
        Private userInputEvents As UserInputEvents

        Public Sub New(inventor As Inventor.Application)
            Me.inventor = inventor
        End Sub

        Public Sub StartHandling()
            userInputEvents = inventor.CommandManager.UserInputEvents
            AddHandler userInputEvents.OnDoubleClick, AddressOf UserInputEvents_OnDoubleClick
            IsActive = True
        End Sub

        Public Sub StopHandling()
            If userInputEvents Is Nothing Then Return

            RemoveHandler userInputEvents.OnDoubleClick, AddressOf UserInputEvents_OnDoubleClick
            userInputEvents = Nothing
            IsActive = False
        End Sub

        Public Property IsActive As Boolean

        Private Sub UserInputEvents_OnDoubleClick(selectedentities As ObjectsEnumerator,
                                                  selectiondevice As SelectionDeviceEnum,
                                                  button As MouseButtonEnum,
                                                  shiftkeys As ShiftStateEnum,
                                                  modelposition As Point,
                                                  viewposition As Point2d,
                                                  view As View,
                                                  additionalinfo As NameValueMap,
                                                  ByRef handlingcode As HandlingCodeEnum)

            Dim sketchedSymbol As SketchedSymbol = Nothing
            For Each entity As Object In selectedentities
                If TypeOf entity Is SketchedSymbol Then
                    sketchedSymbol = entity
                    Exit For
                End If
            Next

            If sketchedSymbol Is Nothing Then
                handlingcode = HandlingCodeEnum.kEventNotHandled
                Exit Sub
            End If


            'Implement your logic here
            Dim msgList As New List(Of String)
            msgList.Add("Name: " & sketchedSymbol.Name)
            msgList.Add("Button: " & [Enum].GetName(GetType(MouseButtonEnum), button))
            msgList.Add("ShiftKeys: " & [Enum].GetName(GetType(ShiftStateEnum), shiftkeys))
            msgList.Add(String.Format("Model position: [{0:N3}, {1:N3}, {2:N3}]", modelposition.X, modelposition.Y, modelposition.Z))
            msgList.Add(String.Format("View position: [{0}, {1}]", viewposition.X, viewposition.Y))

            Dim msg = String.Join(vbCrLf, msgList)
            MsgBox(msg, Title:="OnDoubleClick")

            handlingcode = HandlingCodeEnum.kEventHandled

        End Sub

        Public Sub Dispose() Implements IDisposable.Dispose
            StopHandling()
        End Sub
    End Class