Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
jsrocha74
Posts: 11
Registered: ‎09-21-2012
Message 1 of 12 (490 Views)

setting layer for mleader

490 Views, 11 Replies
09-25-2012 02:50 PM

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

Distinguished Mentor
_Tharwat
Posts: 642
Registered: ‎07-02-2010
Message 2 of 12 (480 Views)

Re: setting layer for mleader

09-25-2012 09:32 PM 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.   :smileywink:

 

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

 Tharwat

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Contributor
jsrocha74
Posts: 11
Registered: ‎09-21-2012
Message 3 of 12 (460 Views)

Re: setting layer for mleader

09-26-2012 11:07 AM in reply to: _Tharwat

Hi, thanks for your reply :smileywink:

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

*Expert Elite*
hmsilva
Posts: 3,335
Registered: ‎12-17-2004
Message 4 of 12 (445 Views)

Re: setting layer for mleader

09-26-2012 01:39 PM 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

*Expert Elite*
hmsilva
Posts: 3,335
Registered: ‎12-17-2004
Message 5 of 12 (435 Views)

Re: setting layer for mleader

09-26-2012 02:14 PM 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

*Expert Elite*
Kent1Cooper
Posts: 5,871
Registered: ‎09-13-2004
Message 6 of 12 (433 Views)

Re: setting layer for mleader

09-26-2012 02:31 PM 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
*Expert Elite*
hmsilva
Posts: 3,335
Registered: ‎12-17-2004
Message 7 of 12 (426 Views)

Re: setting layer for mleader

09-26-2012 03:09 PM 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

Contributor
jsrocha74
Posts: 11
Registered: ‎09-21-2012
Message 8 of 12 (400 Views)

Re: setting layer for mleader

09-27-2012 04:48 AM 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 :smileywink:
Thanks again!

 

jsrocha

*Expert Elite*
hmsilva
Posts: 3,335
Registered: ‎12-17-2004
Message 9 of 12 (394 Views)

Re: setting layer for mleader

09-27-2012 04:58 AM 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

Valued Mentor
Ian_Bryant
Posts: 362
Registered: ‎06-02-2005
Message 10 of 12 (389 Views)

Re: setting layer for mleader

09-27-2012 05:20 AM 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

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.