<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Overwrite double click on sketched symbol in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11021179#M135776</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For production is much better to use it in addin, but for this forum I need some way, how to test the code without any addin implementation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This example is iLogic script and you can start them in standard way by "Run Rule".&lt;/P&gt;&lt;P&gt;After that the shared variable "DoubleClickHandler" is ensured and its value is instance of class "SketchedSymbolDoubleClickHandler". This is because I need to keep the handler alive between rule edits. (Not necessary when you use it in addin.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After that I switch the state of handler Active/Inactive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I implement interface&amp;nbsp;&lt;SPAN&gt;IDisposable for cleanup reason, because I need to remove the event handler. For cleanup I use my own external rule instead of standard&amp;nbsp;SharedVariable.RemoveAll() method. In standard way the list of shared variables is cleared, but if you have an event handler active, the object can not be removed from memory and the event handler is still active.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is my rule to cleanup SharedVariables object. It is little bit hackish, but it works for debugging purposes.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim bindingFlags As Reflection.BindingFlags = System.Reflection.BindingFlags.NonPublic + System.Reflection.BindingFlags.GetField + System.Reflection.BindingFlags.Instance
Dim variables = SharedVariable.GetType().InvokeMember("m_ruleTempStorage", bindingFlags, Nothing, SharedVariable, Nothing)
Logger.Debug(variables.Count)
For Each keyValue In variables
    Dim v = keyValue.Value
    Logger.Debug(v.GetType().Name)
    If TypeOf v Is IDisposable Then
        v.Dispose
        Logger.Debug(" - Disposed")
    End If
Next
SharedVariable.RemoveAll()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The similar solution I use for AddIns also, because I can keep many handlers in one collection and I can clean up them in single For Each loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Mar 2022 12:20:56 GMT</pubDate>
    <dc:creator>Michael.Navara</dc:creator>
    <dc:date>2022-03-22T12:20:56Z</dc:date>
    <item>
      <title>Overwrite double click on sketched symbol</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11020494#M135753</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I programmatically place some sketched symbols in a drawing. When the user double-clicks on such a symbol I want to open a custom dialog and not the standard Inventor dialog.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can this be done?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Stephan&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 06:22:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11020494#M135753</guid>
      <dc:creator>wannensn</dc:creator>
      <dc:date>2022-03-22T06:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite double click on sketched symbol</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11020648#M135755</link>
      <description>&lt;P&gt;You can handle OnDoubleClick event from UserInputEvents. This is a small example how to do it in iLogic. Main code is in class&amp;nbsp;SketchedSymbolDoubleClickHandler. Usage of SharedVariable is necessary to keep the handler alive between rule edits.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    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: " &amp;amp; sketchedSymbol.Name)
            msgList.Add("Button: " &amp;amp; [Enum].GetName(GetType(MouseButtonEnum), button))
            msgList.Add("ShiftKeys: " &amp;amp; [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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 09:28:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11020648#M135755</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2022-03-22T09:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite double click on sketched symbol</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11020803#M135763</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1104556"&gt;@Michael.Navara&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do you "start" the handler? OnOpenDocument event? What if a second drawing is opened? As I see the handler is stopped at this moment. Please, can you explain in short why you implement IDisposable?&lt;/P&gt;&lt;P&gt;Would love to see a solution handling such events in iLogic in a proper way. Until now I always switch to an Addin at this point.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 09:26:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11020803#M135763</guid>
      <dc:creator>Ralf_Krieg</dc:creator>
      <dc:date>2022-03-22T09:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite double click on sketched symbol</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11021179#M135776</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For production is much better to use it in addin, but for this forum I need some way, how to test the code without any addin implementation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This example is iLogic script and you can start them in standard way by "Run Rule".&lt;/P&gt;&lt;P&gt;After that the shared variable "DoubleClickHandler" is ensured and its value is instance of class "SketchedSymbolDoubleClickHandler". This is because I need to keep the handler alive between rule edits. (Not necessary when you use it in addin.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After that I switch the state of handler Active/Inactive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I implement interface&amp;nbsp;&lt;SPAN&gt;IDisposable for cleanup reason, because I need to remove the event handler. For cleanup I use my own external rule instead of standard&amp;nbsp;SharedVariable.RemoveAll() method. In standard way the list of shared variables is cleared, but if you have an event handler active, the object can not be removed from memory and the event handler is still active.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is my rule to cleanup SharedVariables object. It is little bit hackish, but it works for debugging purposes.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim bindingFlags As Reflection.BindingFlags = System.Reflection.BindingFlags.NonPublic + System.Reflection.BindingFlags.GetField + System.Reflection.BindingFlags.Instance
Dim variables = SharedVariable.GetType().InvokeMember("m_ruleTempStorage", bindingFlags, Nothing, SharedVariable, Nothing)
Logger.Debug(variables.Count)
For Each keyValue In variables
    Dim v = keyValue.Value
    Logger.Debug(v.GetType().Name)
    If TypeOf v Is IDisposable Then
        v.Dispose
        Logger.Debug(" - Disposed")
    End If
Next
SharedVariable.RemoveAll()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The similar solution I use for AddIns also, because I can keep many handlers in one collection and I can clean up them in single For Each loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 12:20:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11021179#M135776</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2022-03-22T12:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite double click on sketched symbol</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11021240#M135779</link>
      <description>Thanks, works perfect for me. I use the code in an addin.&lt;BR /&gt;--Stephan</description>
      <pubDate>Tue, 22 Mar 2022 12:40:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/overwrite-double-click-on-sketched-symbol/m-p/11021240#M135779</guid>
      <dc:creator>wannensn</dc:creator>
      <dc:date>2022-03-22T12:40:53Z</dc:date>
    </item>
  </channel>
</rss>

