Stopping a lisp program.

Both Bricscad and Autocad lisp code can not be stopped if you stuff something up and it goes into an endless loop or just never quite gets to the correct answer to exit. It is a question being asked on other forums as well.

If you use a (repeat 50000 a press of esc will stop it use a (while (< x 50000) it will keep going till it gets to 50000 if you have it as a code condition it may never get there.

I am asking the Bricscad guys is there a secret key combo that is undocumented for forcing a stop like CTRL+ALT+DEL which is only way sometimes.

Has it just been left out of the Lisp Interpreter no ultimate exit.

Does Blade have a ultimate stop Acad Vlide greys out anything usefull.

Comments

  • Have run into this very problem & CTRL+ALT+DEL was the only way to stop it, which was very bad because it was a print routine that was stuck in the Ground Hog Day loop; caused the death of countless trees before able to stop it.
    In my case, I use lisp to print & apparently hit Enter right after a print job & it went into the endless loop. It has happened about a half dozen times over the last yr. +.
    A better way to stop it than the ubiquitous CTRL+ALT+DEL would be nice to know.

  • The code below can be stopped with Esc:

    (setq x 0)
    (while (< x 10000000)
      (setq x (1+ x))
    )
    
  • .......or alternatively you can use a user defined keystroke my means of the (cadr (grread nil 2)) function.....
    For example you can use the SPACEBAR to break the loop.

    (defun c:LoopBrake (/ x keystroke)  
    (setq x 0 )
    (while (AND (< x 10000000)(/= keyStroke 32))
      (setq x (1+ x))
    
      (if (= (cadr (grread nil 2)) 32)
              (setq keyStroke 32)
      )
    )
    )
    

    Run the command LOOPBRAKE and hit SPACEBAR....
    You can use another key F12, F11 or B to stop any loop...

  • ...well the loop goes on as long as you keep any other key except SPACEBAR pressed......
    it's just a way to keep the loop going and stop it at some point....not what you want........

  • This will work in BricsCAD, but probably not in AutoCAD:

    (defun c:test ( / x)
      (setq x 0)
      (vl-catch-all-apply
        (function
          (lambda ()
            (while (< x 10000000)
              (if (acet-sys-control-down) (exit))
              (setq x (1+ x))
            )
          )
        )
      )
      (print x)
      (princ)
    )
    
  • Roy,
    If these lines of code are added to any lisp routine that works in BricsCAD, it should stop the loop issue?
    Mike

  • MDunn
    edited January 2021

    Roy,
    Not sure what I am to do w/ your code, please explain.
    Attached is the lisp routine that does the loop after printing & then hitting Enter again, prints endlessly, only way to stop it is CTRL+ALT+DEL .
    It only does the endless loop thing if Enter is hit after the routine is completed, otherwise it only runs the lisp routine once.
    Thanks,
    Mike

  • Thank you every one will try the acet route next time.

  • For Mdunn this is the pdf version but just change printer settings.

  • Alanh,
    Not sure how to use your lisp routine; could you please explain.
    Is there any way to find out why the loop occurs? This started this last yr. sometime, so what is in my lisp routine that causes it? Or is it BricsCAD where the problem is?
    Thanks, Mike

  • @MDunn said:
    .... It only does the endless loop thing if Enter is hit after the routine is completed, otherwise it only runs the lisp routine once. ....

    Mike, it sounds like everything is working great. Your 0BSH custom command does just what you want, and pressing Enter repeats the last command. But why are you pressing Enter if you don't want to repeat it?

  • Anthony,
    The first time it happened was when I accidently hit Enter; you know, one of those “what just happened?”.
    Other times is when another print of the same dwg is needed; & I got way more than I asked for.
    26 yrs. ago I created this lisp routine when I first discovered the value of lisp routines, & have used it in various stages of change because of new printer, added or deleted features, etc. But why is it going into a loop? That is what I want to know.
    Thanks, Mike

  • @MDunn

    I have to remove this line:
    "" ;Returns ext'g; Why is this needed!

    And change:
    (Command "Undo" "Back" "")
    To:
    (Command "Undo" "Back")

  • MDunn
    edited January 2021

    Roy,
    Thank you, your last suggestion is the fix; no longer goes into a loop if Enter hit again!!!
    Cannot remove the 1st "" because it is the answer to the question "Enter paper size or ?"; the "" returns the answer as "ext'g paper size". And I will remove my comment “Why is this needed!” & replace it w/ “Returns ext’g paper size”.
    But your second suggestion does fix the loop issue when hitting enter right after the routine runs. Do not know why I had the "" in there originally, probably because it was needed to run in AutoCAD, which is where I 1st created this lisp routine to run.
    Thank you very much Roy, you be my hero today!
    And thank you to everyone else that was in on this fix, it all added up to a win & saved the lives of many many trees.
    Mike

  • @Roy Klein Gebbinck said:
    And change:
    (Command "Undo" "Back" "")
    To:
    (Command "Undo" "Back")

    Roy,
    Why does that extra Enter, right after the Undo command, repeat the Plot command instead of the Undo command?

  • To Mdunn its a plot range version you can do like plot layout 3-5, 1-99 if 99 is more than actual layouts just does all.

  • @Anthony Apostolaros said:
    Roy,
    Why does that extra Enter, right after the Undo command, repeat the Plot command instead of the Undo command?

    That is a good question. Probably because only commands directly entered in the command bar are added to the command history.

  • Weren't they both executed by the lisp function?

    11 (Command "-PLOT" ;Starts Plot command 32 (Command "Undo" "Back" "") ;Undo Back to Mark, Undoes Layout ranaming

    Maybe the dash in front of PLOT made the difference?

  • As I understand it the c:0BSH function is repeated.

  • So if you run 0BSH once, no problem. But if you immediately run it again by pressing Enter, it crashes. If you run 0BSH, then zoom in or out, then 0BSH again, no problem.

    That just makes it more confusing to me.

  • MDunn
    edited February 2021

    Roy, yes, c:0BSH is the function that is repeated in the never ending loop. But, your suggestion of removing the "" from the Undo Back solved the problem.

    Anthony, yes, prior to Roy's fix, doing any command after printing stops the loop from occurring. An enter after that would just invoke the last command used. OBSH would have to be reinitiated to print again.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Click one of the buttons on the top bar to get involved!