I am trying to add an error handler to a lisp routine to restore previous settings/variables in the event the user hits enter or esc. The attached routine seems to work as desired but if enter or esc is pressed there is no error message. I would like for a message to display if the command is interrupted.
The purpose of the routine is to add a text label (attached block) in paper space by selecting a point in model space and automatically filling in the elevation value as the block is inserted.
Any suggestions to streamline the routine are definitely welcome and appreciated.
Thanks!
(defun C:tocell (/ olderror)
(setvar "CMDECHO" 0)
(setq olderror *error* *error* inserror)
(setq OM (getvar "osmode"))
(setvar "OSMODE" 1)
(setq attdia_org (getvar "attdia"))
(setvar "ATTDIA" 0)
(setq LYR (getvar "clayer"))
(setq LR10 (tblsearch "layer" "G-Text"))
(if (= LR10 nil)
(command "layer" "new" "G-Text" "color" "7" "G-Text" "d" "Standard Text, Leaders, Notes" "G-Text" "lw" ".18" "G-Text" "")
)
(setvar "clayer" "G-Text")
(command "mspace")
(setq Elev (rtos (cadr(getpoint "\nPick Point for Elevation: "))))
(command "pspace")
(setq p1 (getpoint "\n Pick Insertion Point:"))
(command "insert" "S:/CAD_Standards/_SE_Custom/structural/symbols/blocks/Toc-Elev_Left" "_scale" "1" "_rotate" "0" "_non" p1 Elev "" "")
(setvar "clayer" LYR)
(setvar "ATTDIA" attdia_org)
(setvar "osmode" OM)
(prompt "\n:: done ::")
)
;
(defun inserror (msg)
(setvar "OSMODE" OM)
(setvar "ATTDIA" attdia_org)
(command-s "layer" "set" LYR "")
(command-s "pspace")
(setq *error* OLDERROR)
(setq msg1 msg)
(if (= msg "quit / exit abort")
(prompt "\nCommand Cancelled\n")
)
(princ)
)