Hey all
Is there an wasy way of writing your lisps so that if the user presses the escape key during its execution that it exits the program in a desired way? eg restoring settings such as filedia and tilemode before exiting.
Cheers
Hey all
Is there an wasy way of writing your lisps so that if the user presses the escape key during its execution that it exits the program in a desired way? eg restoring settings such as filedia and tilemode before exiting.
Cheers
Post by the offical *error* routine guru:
http://forums.augi.com/showthread.ph...122#post996122
Man has taught classes on the subject here on AUGI.
Tom Beauford P.S.M. - Civil 2013 on Windows 7 Pro
Design Analysis - Leon County Public Works/Engineering
2280 Miccosukee Rd. Tallahassee, FL 32308-5310
Ph# (850)606-1516
Here is an example of what I think you want...
Code:(defun C:TestEscape (/ *error* intCmdEcho strMessage) (setq intCmdEcho (getvar "cmdecho")) (setvar "cmdecho" 0) (defun *error* (strMessage) (setvar "cmdecho" intCmdEcho) (princ strMessage) (princ) ) (print "Do Something: ") (setvar "cmdecho" intCmdEcho) (princ) )
AUGI Volunteer
I prefer to nest the *error* function within the main code, defining the function as a local variable... I also choose to define the localized *error* handler immediately (prior to any system variable changes are made, etc.). While unlikely if not prompting the user for input, it is possible for one to immediately hit escape after a system variable has been changed, and before the *error* handler has been defined, which would result in a system variable value not being restored.
Example:
Code:(defun c:FOO ( / *error* oldCmdecho foo) (defun *error* (msg) (if oldCmdecho (setvar 'cmdecho oldCmdecho) ) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** "))) ) ; Fatal error, display it (princ) ) (if (and (setq oldCmdecho (getvar 'cmdecho)) (setq foo (getstring "\nHit <ESC>)) ) (prompt "\n** You didn't hit <ESC> like I asked you to ** ") ) (*error* nil) )
"Potential has a shelf life." - Margaret Atwood
Another thread discussing the use of nested and global error handlers at length: http://forums.augi.com/showthread.ph...Error-Handling
Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!