(defun c:test (/ var msgg)
;*************************************
(setq var (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq old-error *error*)
(defun *error* (msg)
(setq msgg (strcat "Error!!: " msg))
(princ msgg)
(setq *error* old-error)
(command "_.undo" "_end" "_u")
(exit)
)
(command "_.undo" "_be")
(setq var_OSMODE (getvar "OSMODE"))
(setvar "OSMODE" 1)
;*************************************
(while (= 1 1)
(command "_.line" "0,0,0" "10,10,0" "")
)
;*************************************
(setvar "OSMODE" var_OSMODE)
(setq *error* old-error)
(command "_.undo" "_end")
(setvar "cmdecho" var)
(princ)
)
I'd suggest removing command calls & creating functions using vla-startundomark & vla-endundomark. Also store your lines in a list then you can delete them in the error handler.
(defun c:foo (/ p1 p2 tmp)
;*************************************
(defun *error* (msg)
;; Delete lines
(and tmp (mapcar 'entdel tmp))
(if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
;*************************************
(while (= 1 1)
(command "_.line" "0,0,0" "10,10,0" "")
)
;*************************************
(princ)
)
You're not storing the line in a list (tmp) to delete them. How would the error handler know what to delete?
I'm a little confused on the (= 1 1) 1 will always = 1.
Why not use (while t (command "_.line" "0,0,0" "10,10,0" "")) if your intent is an endless loop exitable only with escape.
Lupo76,
One of the important things about Ron's code is that the *error* function is declared local to the main routine, and does not use the setting and getting of old-error
I noticed that you ignored that.