<?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: Press ESC to stop running ilogic code in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/press-esc-to-stop-running-ilogic-code/m-p/10945634#M134578</link>
    <description>&lt;P&gt;This question looks nice, but is very hard to implement. Because in some cases is not possible to interrupt&amp;nbsp; the execution. For example you can not interrupt execution inside &lt;A href="https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-923F5288-64EA-42F4-B293-52226EF39D42" target="_blank" rel="noopener"&gt;transaction&lt;/A&gt;. &lt;A href="https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-991ABB26-6113-4E27-83F8-1699F259772E" target="_blank" rel="noopener"&gt;More info&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can implement the similar functionality using ProgressBar. See the following example&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 oSketetch As Sketch = ThisDoc.Document.ActivatedObject
    Dim linesCount = 1000

    DrawLinesInSketch(oSketetch, linesCount)
End Sub

Private progressBar As progressBar
Private cancelRequested As Boolean

Sub DrawLinesInSketch(oSketetch As Sketch, linesCount As Integer)

    'Initialze progress bar
    progressBar = ThisApplication.CreateProgressBar(False, linesCount, "Drawing lines", True)
    AddHandler progressBar.OnCancel, AddressOf ProgressBar_OnCancel

    'Draw lines to sketch
    For i As Integer = 1 To linesCount

        'Check if cancel opration is requested
        If cancelRequested Then
            Exit For
        End If

        progressBar.UpdateProgress()

        oSketetch.SketchLines.AddByTwoPoints(
        ThisApplication.TransientGeometry.CreatePoint2d(0, i),
        ThisApplication.TransientGeometry.CreatePoint2d(i, 0)
        )
    Next

    'Cleanup progress bar
    RemoveHandler progressBar.OnCancel, AddressOf ProgressBar_OnCancel
    progressBar.Close()

    'Display final messageBox
    If cancelRequested Then
        MsgBox("Canceled", MsgBoxStyle.Exclamation)
    Else
        MsgBox("Done", MsgBoxStyle.Information)
    End If
End Sub

Private Sub ProgressBar_OnCancel()
    cancelRequested = True
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For more complex task, which doesn't need Inventor for full time, you can use &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.backgroundworker?view=net-6.0" target="_blank" rel="noopener"&gt;BackgroundWorker&lt;/A&gt; and use another thread for computing.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Feb 2022 20:25:01 GMT</pubDate>
    <dc:creator>Michael.Navara</dc:creator>
    <dc:date>2022-02-11T20:25:01Z</dc:date>
    <item>
      <title>Press ESC to stop running ilogic code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/press-esc-to-stop-running-ilogic-code/m-p/10944603#M134555</link>
      <description>&lt;P&gt;I would like to be able to press ESC key while my ilogic rule is running and this will stop the program execution. Is there a way to do this? Would anyone have an example of a program with this feature in it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 12:29:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/press-esc-to-stop-running-ilogic-code/m-p/10944603#M134555</guid>
      <dc:creator>karthur1</dc:creator>
      <dc:date>2022-02-11T12:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Press ESC to stop running ilogic code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/press-esc-to-stop-running-ilogic-code/m-p/10944639#M134557</link>
      <description>&lt;P&gt;I agree somewhat.&amp;nbsp; We definitely need a quick &amp;amp; easy way to stop code execution in some scenarios.&amp;nbsp; This has been requested for some time now.&amp;nbsp; Maybe this will help boost support for the related Ideas in the Inventor Ideas forum.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-ideas/esc-key-stop-ilogic-script/idi-p/7406154" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/inventor-ideas/esc-key-stop-ilogic-script/idi-p/7406154&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-ideas/esc-from-ilogic-editor-edit-rule/idi-p/7582347" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/inventor-ideas/esc-from-ilogic-editor-edit-rule/idi-p/7582347&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-ideas/escape-endless-logic-loop/idi-p/8990847" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/inventor-ideas/escape-endless-logic-loop/idi-p/8990847&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-ideas/esc-key-stop-operation/idi-p/3733288" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/inventor-ideas/esc-key-stop-operation/idi-p/3733288&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 12:51:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/press-esc-to-stop-running-ilogic-code/m-p/10944639#M134557</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-02-11T12:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Press ESC to stop running ilogic code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/press-esc-to-stop-running-ilogic-code/m-p/10945634#M134578</link>
      <description>&lt;P&gt;This question looks nice, but is very hard to implement. Because in some cases is not possible to interrupt&amp;nbsp; the execution. For example you can not interrupt execution inside &lt;A href="https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-923F5288-64EA-42F4-B293-52226EF39D42" target="_blank" rel="noopener"&gt;transaction&lt;/A&gt;. &lt;A href="https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-991ABB26-6113-4E27-83F8-1699F259772E" target="_blank" rel="noopener"&gt;More info&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can implement the similar functionality using ProgressBar. See the following example&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 oSketetch As Sketch = ThisDoc.Document.ActivatedObject
    Dim linesCount = 1000

    DrawLinesInSketch(oSketetch, linesCount)
End Sub

Private progressBar As progressBar
Private cancelRequested As Boolean

Sub DrawLinesInSketch(oSketetch As Sketch, linesCount As Integer)

    'Initialze progress bar
    progressBar = ThisApplication.CreateProgressBar(False, linesCount, "Drawing lines", True)
    AddHandler progressBar.OnCancel, AddressOf ProgressBar_OnCancel

    'Draw lines to sketch
    For i As Integer = 1 To linesCount

        'Check if cancel opration is requested
        If cancelRequested Then
            Exit For
        End If

        progressBar.UpdateProgress()

        oSketetch.SketchLines.AddByTwoPoints(
        ThisApplication.TransientGeometry.CreatePoint2d(0, i),
        ThisApplication.TransientGeometry.CreatePoint2d(i, 0)
        )
    Next

    'Cleanup progress bar
    RemoveHandler progressBar.OnCancel, AddressOf ProgressBar_OnCancel
    progressBar.Close()

    'Display final messageBox
    If cancelRequested Then
        MsgBox("Canceled", MsgBoxStyle.Exclamation)
    Else
        MsgBox("Done", MsgBoxStyle.Information)
    End If
End Sub

Private Sub ProgressBar_OnCancel()
    cancelRequested = True
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For more complex task, which doesn't need Inventor for full time, you can use &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.backgroundworker?view=net-6.0" target="_blank" rel="noopener"&gt;BackgroundWorker&lt;/A&gt; and use another thread for computing.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 20:25:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/press-esc-to-stop-running-ilogic-code/m-p/10945634#M134578</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2022-02-11T20:25:01Z</dc:date>
    </item>
  </channel>
</rss>

