Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
karthur1
384 Views, 2 Replies

Press ESC to stop running ilogic code

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?

 

Thanks

 

 

WCrihfield
in reply to: karthur1

I agree somewhat.  We definitely need a quick & easy way to stop code execution in some scenarios.  This has been requested for some time now.  Maybe this will help boost support for the related Ideas in the Inventor Ideas forum.

https://forums.autodesk.com/t5/inventor-ideas/esc-key-stop-ilogic-script/idi-p/7406154 

https://forums.autodesk.com/t5/inventor-ideas/esc-from-ilogic-editor-edit-rule/idi-p/7582347 

https://forums.autodesk.com/t5/inventor-ideas/escape-endless-logic-loop/idi-p/8990847 

https://forums.autodesk.com/t5/inventor-ideas/esc-key-stop-operation/idi-p/3733288 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Michael.Navara
in reply to: karthur1

This question looks nice, but is very hard to implement. Because in some cases is not possible to interrupt  the execution. For example you can not interrupt execution inside transaction. More info.

 

You can implement the similar functionality using ProgressBar. See the following example

 

 

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

 

 

For more complex task, which doesn't need Inventor for full time, you can use BackgroundWorker and use another thread for computing.