Stop infinite loop in AutoCAD using VsCode

Stop infinite loop in AutoCAD using VsCode

carlos_m_gil_p
Advocate Advocate
1,038 Views
12 Replies
Message 1 of 13

Stop infinite loop in AutoCAD using VsCode

carlos_m_gil_p
Advocate
Advocate

Hello boys how are you.
I wanted to ask if anyone knows how to get out of an infinite loop in AutoCAD using VsCode.
Today by mistake I was working with the while function and I did not set the condition for it to stop.
So it stayed in an infinite loop in autocad, I stopped debugging in vscode and nothing happened in autocad, I also closed vscode completely and the loop continued in autocad.
I tried with the escape key, enter, all possible but I couldn't stop the cycle, the only thing was to enter the application manager and forcefully close autocad.
If anyone knows a method to stop the loop, I would be grateful if you could tell me how to do it.
Greetings.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
1,039 Views
12 Replies
Replies (12)
Message 2 of 13

leeminardi
Mentor
Mentor

A google search said to try Shift+F5.

lee.minardi
0 Likes
Message 3 of 13

Sea-Haven
Mentor
Mentor

I just had same problem this morning, restarted 5 times,  if there is lots of code in your loop so not obvious why its not working you can do say a X+1 if x= 1000 (EXIT), just put the increment X as part of a IF. The (EXIT) is a valid function and will do just that jump out of your lisp that is running, move the IF X till you find the spot that is not working. 

0 Likes
Message 4 of 13

carlos_m_gil_p
Advocate
Advocate

Hello @leeminardi how are you.
I tried to do it with Shift+F5 and it didn't work, I don't know what other option it could be.

It only stops debugging in vscode.


Hello @Sea-Haven how are you.
Yes, it is a very good option, the problem is that I will have to do it whenever I do a while.
In this case, do not place the variable, that is, forget it. And then I couldn't get out of the loop.
That's why I was trying to find an option to stop the loop in AutoCAD.

 

Excuse my English, I only speak Spanish.

Thanks.

 


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 5 of 13

leeminardi
Mentor
Mentor

Hola @carlos_m_gil_p ,  I hope you are well.

 

Have you tried setting breakpoints at the while statements and check if the variables affecting the condition whether or not to continue the loop are changing as you think they should?

https://code.visualstudio.com/docs/editor/debugging

 

 

 

lee.minardi
0 Likes
Message 6 of 13

carlos_m_gil_p
Advocate
Advocate

If I have knowledge about this topic, I also know how to work with while.
It was just an oversight, but I am left wondering, if it were to happen to me at some point, what I could do to resolve it.
Thanks for the contributions.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 7 of 13

EnM4st3r
Advocate
Advocate

similar things also happen to me regularly.. i always have my vscode linked to my autocad session (F5). When it gets stuck in an infinite loop i just tap the reload button and that usually breaks out of the running lisps.

EnM4st3r_0-1712064101483.png

 

0 Likes
Message 8 of 13

carlos_m_gil_p
Advocate
Advocate

Hello brother, thanks for your help, but it didn't work for me.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 9 of 13

Sea-Haven
Mentor
Mentor

Yep can occur with lisp also and just use task manager to stop. Tried all the normals ESC CTrl+c Break and so on.

0 Likes
Message 10 of 13

EnM4st3r
Advocate
Advocate

hm, maybe your VSC is not attached to AutoCAD correctly or its not setup correct?
I for example tried this loop and it breaks out as i said

 

(defun c:whilebreak (/ a)
  (setq a 0)
  (while t 
    (setq a (1+ a))
  )
)

 

0 Likes
Message 11 of 13

carlos_m_gil_p
Advocate
Advocate

Hello @EnM4st3r how are you.
Thanks for continuing to help.
In your example the while condition is T, which means that if you press ESC it will return NIL and stop it.
Try this example I show.

 

(defun c:xxx (/) 
  (setq cont t)
  (while cont 
    (if 
      (and 
        (not (vl-catch-all-error-p (setq pt (vl-catch-all-apply 'getpoint))))
        (not (null pt)))
      (setq cont t)))
  (exit))

 


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Message 12 of 13

EnM4st3r
Advocate
Advocate

hm, that rly doesnt work with your example.. thought my example would be the same since hitting ESC also does not work for me with it. Maybe post an issue report here?


https://github.com/Autodesk-AutoCAD/AutoLispExt/issueshttps://github.com/Autodesk-AutoCAD/AutoLispEx...

Message 13 of 13

carlos_m_gil_p
Advocate
Advocate

Thanks, I already did it.


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes