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

setting layer for mleader

11 REPLIES 11
Reply
Message 1 of 12
jsrocha74
2741 Views, 11 Replies

setting layer for mleader

Hy guys, how´s going?

i have a few simple routines that i use to set a especific layer before some commands, such as texts, dimensions, haches, etc... i was trying to do the same with mleader, but i´m not getting there. Here is the code i use for text:

 

(defun c:rrt (/ cla)
(setq eco (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq ERRO_ORIGINAL *error*)
(setq *error* ERRO)
(setq cla (getvar "clayer"))
(if(not(tblsearch "layer" "texo"))
(command "layer" "m" "texto" "c" "2" "" "")
(setvar "clayer" "texto")
)
(setq textloc (getpoint "
Text Position: " ))""
(command "_Dtext" textloc 0 )
(while (>(getvar "cmdactive") 0)
(command pause))
(setvar "clayer" cla)
(setvar "cmdecho" eco)
(setq *error* ERRO_ORIGINAL)
(princ)
)

 

is there a way to use this code with mleader command? i tried to edit to use with mtext to, but i didn´t work either. 

thanks in advance,

 

Jsrocha

11 REPLIES 11
Message 2 of 12
_Tharwat
in reply to: jsrocha74

The problem is with the layer name it self .

 

You are checking if the layer name texo is found in Layer table and trying to make the layer texto is on which may not

found in the current drawing  ( texo is different than texto ) in writting.   Smiley Wink

 

  (if (not (tblsearch "layer" "texo"))
    (command "layer" "m" "texto" "c" "2" "" "")
    (setvar "clayer" "texto")
    )

 Tharwat

Message 3 of 12
jsrocha74
in reply to: _Tharwat

Hi, thanks for your reply 😉

i noticed that the search line has an error, but this is not the problem, the code work for texts and dimensions. What i´m trying to do is use this code to draw a mleader in a especific layer.

Cheers,

 

Jsrocha

Message 4 of 12
hmsilva
in reply to: jsrocha74

Hi Jsrocha,

try something like

 

(defun c:test (/ cla eco)
(setq eco (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq ERRO_ORIGINAL *error*)
(setq *error* ERRO)
(setq cla (getvar "clayer"))
(if(not(tblsearch "layer" "texto"))
(command "layer" "m" "texto" "c" "2" "" "")
(setvar "clayer" "texto")
)
(setvar "cmdecho" eco)
(command "_mleader")
(while (>(getvar "cmdactive") 0)
(command pause))
(setvar "clayer" cla)
(setq *error* ERRO_ORIGINAL)
(princ)
)

 

Henrique

EESignature

Message 5 of 12
hmsilva
in reply to: jsrocha74

Jsrocha

another way

 

(defun c:test1 (/ cla eco lay)
  (setq eco (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq cla (getvar "clayer"))
  (setq lay (tblsearch "LAYER" "texto"))
  (if (null lay)
    (prompt "\nCreating layer - texto ")
    (progn
      (if (= (logand 1 (cdr (assoc 70 lay))) 1)
    (command "_.LAYER" "_T" "texto" "")
      )
    )
  )
  (command "_.LAYER" "_M" "texto" "C" "2" "" "")
  (initcommandversion 2)
  (setvar "cmdecho" eco)
  (command "_mleader")
  (while (> (getvar "cmdactive") 0)
    (command pause)
  )
  (setvar "clayer" cla)
  (princ)
)

 

Henrique

EESignature

Message 6 of 12
Kent1Cooper
in reply to: hmsilva


@hmsilva wrote:

....

try something like

....

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


My AutoCAD is too old to have Multi-Leaders, but I tried something like that with a regular Leader, and when the command got to the annotation part, it got all endless-loopy on me, feeding in eternal backslashes from the pauses, as though they were supposed to be lines of text content.  I'm not sure how to get around that, unless you can specify the text content ahead of time for a single line or limited lines, and somehow feed that in at the point where the User has given the last leader definition point -- probably have to be looking at (getvar 'lastprompt) or something.

 

But beyond that, if the text looping isn't a problem with Mleaders or with newer versions of AutoCAD somehow, there are some simplifications you can make.

 

The *error* routine can be defined as a sub-routine and localized like a variable, so it will revert to what it was when the routine is over, which means you don't need to save the current one and restore it.  Multiple variables can be set in one (setq) function.  And if you Make a Layer, it becomes current in the process, so you don't need to set it current, and you don't even need to check for it -- Making it won't have any problem if it already exists.  And a less significant one: system variable names can have a single-quote only before them, instead of double-quotes at both ends.

 

(defun c:test (/ *error* eco cla)

  (defun *error* () (ERRO))
  (setq

    eco (getvar 'cmdecho)

    cla (getvar 'clayer)

  ); setq
  (setvar 'cmdecho 0)
  (command "_.layer" "_t" "texto" "_m" "texto" "_c" "2" "" "")
  (setvar 'cmdecho eco)
  (command "_.mleader")
  (while (> (getvar 'cmdactive) 0)
    (command pause);;;;; this is where Leader has a problem for me....

  ); while
  (setvar 'clayer cla)
  (princ)
)

 

EDIT:  hmsilva's second suggestion reminded me about the possibility of the Layer being there already, but being frozen, but that can be handled pretty simply -- I added the Thawing in the Layer command.  That covers for the possibility [the Make option will have a problem if it's frozen, because it won't be able to set it current].  The Thaw option will not have any problem if the Layer doesn't exist yet.

Kent Cooper, AIA
Message 7 of 12
hmsilva
in reply to: Kent1Cooper

HI Kent Cooper,

tested your code in AC2011 and gives no error, adding the Thawing in the Layer command
is a good way to solve the problem if the layer is frozen.

(defun c:test (/ *error* eco cla)
  (defun *error* () (ERRO))
  (setq
    eco    (getvar 'cmdecho)
    cla    (getvar 'clayer)
  ); setq
  (setvar 'cmdecho 0)
  (command "_.layer" "_t" "texto" "_m" "texto" "_c" "2" "" "")
  (initcommandversion 2);;;For multiline text
  (setvar 'cmdecho eco)
  (command "_.mleader")
  (while (> (getvar 'cmdactive) 0)
    (command pause)
  ); while
  (setvar 'clayer cla)
  (princ)
)


I just add in your code

(initcommandversion 2)

for multiline text if necessary, otherwise will be a single line text.

Henrique

EESignature

Message 8 of 12
jsrocha74
in reply to: jsrocha74

Hi guys, thanks for your help!
hmsilva, you made it! the second code you posted is exactly what i need, works perfectly! the first one works too, but it allows only one line of text, and i like to use the mline tool to write te text (just like in the second code 😉
Thanks again!

 

jsrocha

Message 9 of 12
hmsilva
in reply to: jsrocha74

jsrocha,

 

the code that Kent Cooper post, does what you need,

and is cleaner, more organized and simple that my.

 

See the code I ad   (initcommandversion 2);;;For multiline text

 

Henrique

EESignature

Message 10 of 12
Ian_Bryant
in reply to: Kent1Cooper

Kent wrote:

My AutoCAD is too old to have Multi-Leaders, but I tried something like that with a regular Leader, and when the command got to the annotation part, it got all endless-loopy on me, feeding in eternal backslashes from the pauses, as though they were supposed to be lines of text content.  I'm not sure how to get around that,

 

Hi Kent,

if you want to use your code, but using leader or qleader commands,

you need to set the system variable "TEXTEVAL" to 1

before running the command loop,

 

Regards Ian

 

Message 11 of 12
Kent1Cooper
in reply to: Ian_Bryant


@Ian_Bryant wrote:

@KenT wrote:

....when the command got to the annotation part, it got all endless-loopy on me,....

 

Hi Kent,

... you need to set the system variable "TEXTEVAL" to 1....


That's it!  [Now, the question is whether I will remember that the next time a situation like this comes up....]

Kent Cooper, AIA
Message 12 of 12
pendean
in reply to: Kent1Cooper

Late Post to an old thread, but if anyone reads this for some of the excellent tips above please note that hey use LAYER command's MAKE option, which will (quoting from HELP):

 

"-Creates a layer and makes it current. New objects are drawn on the current layer.

 

-If no layer exists for the name you enter, a new layer with that name is created. The new layer is on and assumes the following properties by default: color number 7, the CONTINUOUS linetype, and a lineweight of DEFAULT.

 

-If the layer exists but is turned off, it is turned on."

 

So there is no need to first search of the layer, then create if it's missing, then set it as current as some of the coding shows above in some of the replies. Hope that helps someone.

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

Post to forums  

Autodesk Design & Make Report

”Boost