UNDO inside a Lisp error handler

By Adam Nagy

If you want to call the UNDO command from an error handler then instead of using (command) you need to use (vla-SendCommand)

(defun C:test ()
   (setq olderr error
     error myerr)
   (command “undo” “_m”)
   (command “_line” ‘(0 0 0) ‘(10 10 0) “”)
   ; If you press esc when line is asking for the second point
   ; then myerr will be called by the system
   (command “_line” ‘(0 0 0) “\” “”)
   (setq *error* olderr)
)

(defun myerr (msg)
   (vl-load-com)
   (setq *error* olderr)

   ; Instead of using (command) …
   ; (command “_undo” “b”)
   ; use vla-SendCommand:
   (vla-SendCommand
     (vla-get-ActiveDocument
       (vlax-get-acad-object))
         (strcat (chr 27)(chr 27)”
.undo _b “))

   (princ)
)


Comments

One response to “UNDO inside a Lisp error handler”

  1. I’m assuming the reason is that there might be a command active?
    I was using the following to get around that issue:
    (if (= 0 (getvar “cmdactive”)) (command “undo” “1” “regen”))
    With my method the command line is clean when CMDECHO is 0. With vla-SendCommand I’m not sure if there is a way to suppress all the command line echoing.

Leave a Reply to GTCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading