Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to stop an iLogic loop with the keyboard

35 REPLIES 35
SOLVED
Reply
Message 1 of 36
Anonymous
8584 Views, 35 Replies

How to stop an iLogic loop with the keyboard

Hi,

 

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

 

 

Thanks,

 

Pascal Langlais

35 REPLIES 35
Message 21 of 36
arron.craig
in reply to: Anonymous

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

Message 22 of 36
MjDeck
in reply to: arron.craig

@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.

Message 23 of 36
Anonymous
in reply to: MjDeck

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

Message 24 of 36
Luisfmts
in reply to: Anonymous

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

Message 25 of 36
jfenter
in reply to: Anonymous

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

Message 26 of 36
Leonardo_Czuy
in reply to: Anonymous

I am in 2023, This feature was added?

Message 27 of 36
MjDeck
in reply to: Anonymous

@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.

Message 28 of 36
MjDeck
in reply to: Anonymous

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.

Message 29 of 36
Frederick_Law
in reply to: Anonymous

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.

Message 30 of 36
mfoster9TD82
in reply to: Anonymous

Any progress on this?

Message 31 of 36
tbillsKGJL5
in reply to: Anonymous

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.

Message 32 of 36
Jpfeifer5TC7R
in reply to: Anonymous

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. 

Message 33 of 36
bradeneuropeArthur
in reply to: Anonymous

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 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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 !

Message 34 of 36
Luisfmts
in reply to: Jpfeifer5TC7R

That is indeed a smart workaround!
Thanks for sharing.
Message 35 of 36


@Jpfeifer5TC7R wrote:

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

 

Credit:

@Curtis_Waguespack 

 

 


@Jpfeifer5TC7R, 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

 

Message 36 of 36
WCrihfield
in reply to: Jpfeifer5TC7R

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)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report