owenwengerd - I definitely press escape only once.
VovKa - Actually that helped in the beginning. I don't know why, but using foreach instead of mapcar helped for the initial code.
Escaping during test1 I got this:
Command: TEST1
"3" < color on start test
"1" < color after cecolor 1
"1" < color on start *error*
"3" < color after variavle reset using foreach *error*
"3" < color after endundomar *error*
Command:
Command: *Cancel*
Then I tried to add also UCS reset to *error* and it broke again. Note that error worked untill the moment it reached UCS reset part.
Escaping during test1 I got this:
Command: TEST2
"3" < color on start test
"1" < color after cecolor 1ucs
Current ucs name: *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: z
Specify rotation angle about Z axis <90d0'0">: 45
Command:
"UCS rotated"
"1" < color on start *error*
"3" < color after variavle reset using foreach *error*Function cancelled
Command: *Cancel*
Here are 2 codes that I used:
(defun c:test2 (/ i val *error*)
(defun *error* (msg)
(print (getvar "cecolor"))
(princ " < color on start *error*")
(foreach v val (setvar (car v) (cdr v)))
(print (getvar "cecolor"))
(princ " < color after variavle reset using foreach *error*")
(command-s "_.ucs" "_w")
(print "UCS reset *error*")
(if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
(princ (strcat "\nError: " msg))
)
(vla-endundomark adoc)
(print (getvar "cecolor"))
(princ " < color after endundomar *error*")
)
(vl-load-com)
(vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(print (getvar "cecolor"))
(princ " < color on start test")
(setq val (mapcar (function (lambda (v) (cons v (getvar v)))) '("clayer" "cecolor")))
(setvar "cecolor" "1")
(print (getvar "cecolor"))
(princ " < color after cecolor 1")
(command "ucs" "z" "45")
(print "UCS rotated")
(setq i 1)
(while (< i 5000000) (setq i (1+ i)))
(setvar "cecolor" "2")
(print (getvar "cecolor"))
(princ " < color after cecolor 2 (while completed)")
(*error* nil)
(print (getvar "cecolor"))
(princ " < color on end test")
)
(defun c:test1 (/ i val *error*)
(defun *error* (msg)
(print (getvar "cecolor"))
(princ " < color on start *error*")
(foreach v val (setvar (car v) (cdr v)))
(print (getvar "cecolor"))
(princ " < color after variavle reset using foreach *error*")
(if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
(princ (strcat "\nError: " msg))
)
(vla-endundomark adoc)
(print (getvar "cecolor"))
(princ " < color after endundomar *error*")
)
(vl-load-com)
(vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(print (getvar "cecolor"))
(princ " < color on start test")
(setq val (mapcar (function (lambda (v) (cons v (getvar v)))) '("clayer" "cecolor")))
(setvar "cecolor" "1")
(print (getvar "cecolor"))
(princ " < color after cecolor 1")
(setq i 1)
(while (< i 5000000) (setq i (1+ i)))
(setvar "cecolor" "2")
(print (getvar "cecolor"))
(princ " < color after cecolor 2 (while completed)")
(*error* nil)
(print (getvar "cecolor"))
(princ " < color on end test")
)
Marc'Antonio AlessiYour version still did not work for me.
Actually can I ask everyone who is reading this topic to test my initial code from post 1 and post what is the outcome for you? I would appreciate if at least some of you do that. I do not understand how this code can work for Marc'Antonio Alessi and not work for me. Your tests would at least be informative to understand if something is wrong on my computers.