Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

How to stop an iLogic loop with the keyboard

Anonymous

How to stop an iLogic loop with the keyboard

Anonymous
Not applicable

Hi,

 

Is it possible to stop an infinite loop when running an iLogic rule?

 

 

Thanks,

 

Pascal Langlais

0 Likes
Reply
Accepted solutions (1)
9,071 Views
35 Replies
Replies (35)

arron.craig
Collaborator
Collaborator

I wonder if this will be added in 2020....

MjDeck
Autodesk
Autodesk

@arron.craig, do you have Visual Studio installed? If so you can use it to attach to the Inventor 2019 process and then "Break All".  This will most likely jump right to your rule code in Visual Studio. You might be able to break out of the loop that's currently running. And if you can't break out, you can at least step though the statements in the loop to find out why it's stuck.


Mike Deck
Software Developer
Autodesk, Inc.

Anonymous
Not applicable

I figured it out. The vb file is stored in

 

appdata\Local\Temp\iLogic Rules

 

if its not there, go back to \Temp and find the most recent .out (moldDesignFileHandler) file and open it in visual studio. this gave me the location where all of my inventor vb files were saved.

 

this just saved me a days worth of work

 

hope this helps

 

inventor professional 2019

0 Likes

Luisfmts
Enthusiast
Enthusiast

2021, and in few months it will be its 10th birthday 😋:birthday_cake: 

jfenter
Enthusiast
Enthusiast

Still waiting in 2021..... 10 years is a long time to wait.  I hope the OP shut down his computer by now.

Leonardo_Czuy
Advocate
Advocate

I am in 2023, This feature was added?

0 Likes

MjDeck
Autodesk
Autodesk

@Leonardo_Czuy , in Inventor 2023 and 2024 there is no easy way to stop an infinite loop. However, if you have Visual Studio you can attach to the Inventor process and debug to try to find out why the rule is stuck in a loop.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes

MjDeck
Autodesk
Autodesk

If you know that a loop might run too long (or forever) in some situations, you can add code to check if a key is down and exit the loop in that case. See the attached rule for a sample. With that Keyboard class in your rule, you would add checking code such as the following in each loop:

ThisApplication.UserInterfaceManager.DoEvents
Dim keyDown = Keyboard.IsKeyDown(Keys.ShiftKey)
If keyDown Then
	Logger.Debug("shift key down = {0}. Exiting loop.", keyDown)
	Exit For ' use Exit Do for Do loops, or Exit While for While loops
End If

Mike Deck
Software Developer
Autodesk, Inc.

Frederick_Law
Mentor
Mentor

iLogic debug is available since 2019 with VS:

https://modthemachine.typepad.com/my_weblog/2019/12/using-visual-studio-to-debug-ilogic-rules.html

 

Just tested with VS2022 Community on IV2023.

mfoster9TD82
Advocate
Advocate

Any progress on this?

0 Likes

tbillsKGJL5
Participant
Participant

I agree that iLogic is not supposed to be a complete end-all-be-all programming tool, but any development environment with the ability to form inescapable "do while" loops really ought to have some kind of Keyboard shortcut to act as a sequence breaker, regardless of scope. To not have this tool available feels grossly negligent.

0 Likes

J_Pfeifer_
Advocate
Advocate

Going to pass on some amazing knowledge I was given awhile back when I ran into an infinite loop myself. If you know you're going to be testing a loop or know that it could end up in an endless state use the following code. 

 

oFile = "C:\Temp\Endless Loop Saftey File.txt"
	If IO.File.Exists("C:\Temp\Endless Loop Safety File.txt") = False Then
		MsgBox("The rule called '" & iLogicVb.RuleName & "' stopped because text file doesn't exist:" & vbLf & oFile, , "iLogic")
		Exit Sub
	End If

 

Then create a Text file named "Endless Loop Safety file.txt inside a temp folder placed onto the C drive. Now when ever that loop enters an endless state, you can rename the file to break the loop without crashing the software and losing work.

 

Credit:

@Curtis_Waguespack 

 

In agreement with many here, tons of things go years without being addressed when it comes to the "Ideas" thread. Some pretty basic stuff that could be improved or implemented without notice. 

bradeneuropeArthur
Mentor
Mentor

Creating an add in and creating you own command definition would be possibly the easier way, since you can than cancel the command.

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

Luisfmts
Enthusiast
Enthusiast
That is indeed a smart workaround!
Thanks for sharing.
0 Likes

Curtis_Waguespack
Consultant
Consultant

@J_Pfeifer_ wrote:

Going to pass on some amazing knowledge I was given awhile back...

 

Credit:

@Curtis_Waguespack 

 

 


@J_Pfeifer_, To be fair, I "swiped" that code, likely from this forum... or somewhere else online... and then just incorporated it into some of my work. And then and just passed it along when I saw there was a need for it in your work.

 

I wish I was better at remembering who/where I get pieces like that from... but in any case a big thank you to everyone that contributes gems like that to this forum!

 

Curtis_Waguespack_0-1721918117403.jpeg

 

0 Likes

WCrihfield
Mentor
Mentor

The other one I use sometimes, but is also not the most convenient, is the ProgressBar (when the Cancel button is allowed upon creation) and its ProgressBar.OnCancel Event , which is a tool that already exist in the Inventor API.  There is an 'API Sample', but that sample is not include showing the cancel button, or handling the OnCancel event. 

 

Years ago, although I had used it for some situations on occasion, I was skeptical about using it for situations where I may need to escape an endless loop type scenario, because I did not understand that much about 'threads / multi-thread processing' (and am still not an 'expert' in that area'), and I know that the ProgressBar was part of Inventor, and that Inventor may be frozen up at the time.  But later, I heard from a couple people including @JelteDeJong(in his Blog post) that, when set-up properly, it actually works on a different thread than the loop is running on, so it was a viable candidate for that type of use.  So, I often find myself incorporating that into my code solutions where a code could take a long time to run.  I do generally try to avoid using Do...Loop, While...End While, and similar types loops, when possible, but have found a few places where they seem to be the better option, and in those cases, I may incorporate this also.

 

It is somewhat advanced though, because it does involve multi-sectional code layout, and the creation and use of EventHandler(s) to monitor some of Inventor's Events (not the iLogic Event Triggers), which most beginners do not understand much about yet, so maybe not a one size fits all type 'workaround'.

 

A had also heard about multiple similar ideas to the text file thing, where you would have a line of code within your loop that checks for something outside of Inventor's scope, but did not like the idea, due to most of my stuff being used by several other folks sometimes, and not having any control over things like that on other peoples computers.

 

All these types of ideas all seem to come down to the same basics though...having the forethought to either avoid creating a loop that may end up being endless in the first place, or having the forethought to include something special like one of these ideas within the loop as you create it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)