You should be able to put *all* of the qleader
input [points and annotation] into a wait-until-the-command-is-finished segment,
and have it restore the Layer afterwards:
....
(command "qleader")
(while (> (getvar 'cmdactive) 0) (command pause))
(setvar "clayer"
LECLAY)
....
One advantage of that over your original, and
something like what devitg suggested, is that it will work equally well no
matter how many line segments you have imposed as a limit on your
Qleaders. You can change that without having to re-write the code for a
different number of pauses.
And as I often point out, you can eliminate the
check on whether the Layer exists. You can simply Make the Layer, and if
it exists already, it won't care, but if it doesn't, it will create it and make
it current [and therefore the default for color assignment] all in one
operation. You can replace all of this:
(if (TBLSEARCH
"layer" "LS-PS Text")
(setvar "clayer" "LS-PS Text")
(command "layer" "n"
"LS-PS Text" "c" "4" "LS-PS Text" ""))
with just this:
(command
"layer" "m" "LS-PS Text" "c" "4" "")
The only reason you might want to check first is
if, in the case that the Layer exists with a non-standard color, you
want to let the User keep it "wrong" that way. But even then, you
should use the Make option in the 'else' argument, because as you have
it, it will create the new Layer, but it won't become the current
Layer.
--
Kent Cooper
I'm trying to do a simple adjustment to the qleader command so
that the current layer switches to my labeling layer to execute the leader/label
then switches back to the original clayer. Problem I have is that after
executing the command, the leader ends up on the correct labelling layer, but
the text for that leader ends up on the original clayer. Seems like it'd be a
simple lisp, but I don't know why it's doing this. Here's the
code:
(defun c:LE ( / LECLAY)
(setvar "cmdecho" 0)
(setq LECLAY
(getvar "clayer"))
(setvar "cmdecho" 1)
(if (TBLSEARCH "layer" "LS-PS
Text") ; Check for layer name
(setvar "clayer" "LS-PS Text")
(command
"layer" "n" "LS-PS Text" "c" "4" "LS-PS Text" ""))
(command "qleader" pause
pause pause)
(setvar "clayer" LECLAY)
(princ)
)