Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 6
andrewscott99
248 Views, 5 Replies

ESC key

Hi

My following routine creates a dimension on the correct layer and restores the previous layer. If some hits ESC before the command is complete it will not restore the previous layer. Is there anything i can do to make sure the previous layer is restored even if the user hits the ESC key?

(defun c:DL ()
(setq lay (getvar "clayer"))
(setq sc (itoa (getvar "useri1")))
(setq ds (strcat "DyerDim" sc))
(setq layname (strcat "05-Dim" sc))
(command "layer" "make" layname "color" "2" "" "")
(Command "-dimstyle" "restore" ds)
(Command "dimlinear")
(while (< 0 (getvar "cmdactive"))
(command pause)
)
(setvar "clayer" lay)
(setq dim (strcat "Dimension created using " ds " with layer " layname))
(prompt dim)
(princ)
)
5 REPLIES 5
Message 2 of 6

create an error.lsp file and load it from any of the commonly used files... acad.lsp, acaddoc.lsp or Enterprise.mnl file.
in the body of the error routine include something like this - (copied straight from our error.lsp file):

[code]
(foreach val (list "$dynmode" "$sdi" "$clayer" "$osmode" "$dimzin" "$attreq" "$attdia" "$cmddia" "$pickstyle"
"$highlight" "$orthomode" "$autosnap" "$modemacro")
(if (and (getvar (substr val 2)) ; added 2007 support, not a legal var don't run this
(eval (read val)) ; if user pref has been saved
)
(progn
(setvar (substr val 2) (eval (read val))) ; reset the var to user pref
(set (read val) nil) ; set the variable equal to nil
)
)
)
[/code]
I use this $setvar format for all the variables that I wish to restore to user's preference.

you can find the standard error routine in the online help.
Message 3 of 6

Thanks, i'll give it a go.
Message 4 of 6
Tom Smith
in reply to: andrewscott99

You need an error handler, preferably one which is specific to your purposes. In this case, it doesn't need to do a thing in the world but restore your saved "lay" variable.

This has been discused in detail dozens of times, and many examples have been posted.

A very simple form would be:

(defun c:DL (/ *error* lay sc ds layname )
(defun *error* (msg)
(setvar "clayer" lay)
(princ))
(setq lay (getvar "clayer"))
(setq sc (itoa (getvar "useri1")))
(setq ds (strcat "DyerDim" sc))
(setq layname (strcat "05-Dim" sc))
(command "layer" "make" layname "color" "2" "" "")
(Command "-dimstyle" "restore" ds)
(Command "dimlinear")
(while (< 0 (getvar "cmdactive"))
(command pause)
)
(setq dim (strcat "Dimension created using " ds " with layer " layname))
(prompt dim)
(*error* nil)
)

Note that all of your variables should be declared local as shown.
Message 5 of 6

Very simple, thanks.
Message 6 of 6
Tom Smith
in reply to: andrewscott99

Hope it works out for you.

Another common scenario, besides clayer, is a routine that changes osmode temporarily. The same approach would apply there.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost