Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Qleader command adjustment not working

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
262 Views, 9 Replies

Qleader command adjustment not working

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)
)

Thanks in advance!
9 REPLIES 9
Message 2 of 10
devitg
in reply to: Anonymous

Give it a try

(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" ""))
(setq text (getstring "\n input the text"))
(command "qleader" pause pause pause 0 text "" );_ you need to state the 0 .
(setvar "clayer" LECLAY)
(princ)
)
Message 3 of 10
Anonymous
in reply to: Anonymous

Although the new routine you posted does place the text on the correct layer, it doesn't quite work out for my purposes.
I am unable to create multi-lined labels by collecting the label info and placing it in the "text" variable.
I also didn't see the need to include the "0" in yours as well.
I took it out and it worked correctly without it.

I just figured it out:

(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")
(command pause)
(setvar "clayer" LECLAY)
(princ)
)
Message 4 of 10
Anonymous
in reply to: Anonymous


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)
)
Message 5 of 10
Anonymous
in reply to: Anonymous

Thanks Kent...good point on the If/then Layer Check...I have a lot of routines I've done that with that I can adjust and slim up a bit there.
As for the other issue of doing the while, I posted a reply, just before yours with a code that worked on a similar tip, that works.
Is there something in the way I did it that is a cause for concern?

Thanks again!
Message 6 of 10
Anonymous
in reply to: Anonymous


If you're talking about your response to devitg,
I'm a little surprised if that works as you expect, when you start out in some
other Layer.  It only has one pause in it -- this:

 

(command
"qleader")
(command pause)


face="Times New Roman" size=3>
is equivalent to
this:


face=Arial size=2>
 

(command "qleader" pause)

 

That should mean that as soon as you
give it the first point of the Qleader, the pause has done its job, and it
should go on to reset the Layer, and the end of the routine should leave you in
the Qleader command's prompt for the next point.  That should only result
in the text being on the right Layer if you *started* in that Layer,
because it would then be setting it "back" to that Layer, but also *from* that
Layer.

 

The (while > (getvar 'cmdactive) 0) (command
pause)) approach keeps an eye on whether a command [in this case Qleader] is
running, and as long as it is, it will keep on pausing for user input. 
Only when the Qleader command is done, and the CMDACTIVE System Variable value
returns to 0, will it move on to the next thing in the routine, namely setting
the current Layer back to what it was when you started.


face=Arial size=2>

--
Kent
Cooper

 

 

Thanks Kent...good point on the If/then Layer Check...I have a lot
of routines I've done that with that I can adjust and slim up a bit there. As
for the other issue of doing the while, I posted a reply, just before yours with
a code that worked on a similar tip, that works. Is there something in the way I
did it that is a cause for concern? Thanks again!
Message 7 of 10
Anonymous
in reply to: Anonymous

You were right about my previous post...it didn't work as I originally thought.

I implemented your changes...the layer check needed a little tweaking...no biggie...

But the while function resulted in a label whole bunch of /P/P/P/P/P/P/P/P/P/P/P ETC that persisted until I hit ESC.

Don't see what's causing that.

I'm in 2008, BTW



Here's the current code:



(defun c:LE ( / LECLAY)

(setvar "cmdecho" 0)

(setq LECLAY (getvar "clayer"))

(command "layer" "m" "LS-PS Text" "c" "4" "LS-PS Text" "")

(setvar "cmdecho" 1)

(command "qleader")

(while (> (getvar "cmdactive") 0) (command pause))

(setvar "clayer" LECLAY)

(princ)

)
Message 8 of 10
Anonymous
in reply to: Anonymous


The Layer thing can be just:

 

(command "layer" "m" "LS-PS Text" "c" "4" ""
""))

[I left out a pair of double-quotes before -- the
first pair assigns the color to the default Layer (no need to spell it out
again), and the second pair ends the command.]

 

The /P/P/P/P/P thing would appear to be an
interpreting of (command pause) within the annotation part of Qleader as
/P, which of course it would do repeatedly if that's how it reads that.  I
don't have 2008, so I don't know....


--
Kent
Cooper

 

 

You were right about my previous post...it didn't work as I
originally thought.
I implemented your changes...the layer check needed a
little tweaking...no biggie...
But the while function resulted in a label
whole bunch of /P/P/P/P/P/P/P/P/P/P/P ETC that persisted until I hit
ESC.
Don't see what's causing that.
I'm in 2008, BTW

size=2>....

(defun c:LE ( / LECLAY)
(setvar "cmdecho" 0)
(setq
LECLAY (getvar "clayer"))
(command "layer" "m" "LS-PS Text" "c" "4" "LS-PS
Text" "")
(setvar "cmdecho" 1)
(command "qleader")
(while (> (getvar
"cmdactive") 0) (command pause))
(setvar "clayer"
LECLAY)
(princ)
)
Message 9 of 10
Anonymous
in reply to: Anonymous

I found my answer in the form of a system variable flip.
texteval needs to be 1.

here's the completed code:

(defun c:LE ( / LETE LECLAY)
(setq LETE (getvar "texteval"))
(setvar "cmdecho" 0)
(setvar "texteval" 1)
(setq LECLAY (getvar "clayer"))
(command "layer" "m" "LS-PS Text" "c" "4" "" "")
(setvar "cmdecho" 1)
(command "qleader")
(while (= (getvar "cmdactive") 1) (command pause))
(setvar "clayer" LECLAY)
(setvar "texteval" LETE)
(princ)
)

Thanks for the help!
Message 10 of 10
Anonymous
in reply to: Anonymous


Way to go.  TEXTEVAL is one of those that
doesn't usually occur to me, so thanks for the reminder.

--
Kent
Cooper

 

 

I found my answer in the form of a system variable
flip.
texteval needs to be 1.

here's the completed code:

(defun
c:LE ( / LETE LECLAY)
(setq LETE (getvar "texteval"))
(setvar "cmdecho"
0)
(setvar "texteval" 1)
(setq LECLAY (getvar "clayer"))
(command
"layer" "m" "LS-PS Text" "c" "4" "" "")
(setvar "cmdecho" 1)
(command
"qleader")
(while (= (getvar "cmdactive") 1) (command pause))
(setvar
"clayer" LECLAY)
(setvar "texteval" LETE)
(princ)
)

Thanks for
the help!

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

Post to forums  

Autodesk Design & Make Report

”Boost