AutoCAD LT lisp assistance

AutoCAD LT lisp assistance

DC-MWA
Collaborator Collaborator
1,259 Views
14 Replies
Message 1 of 15

AutoCAD LT lisp assistance

DC-MWA
Collaborator
Collaborator

Hello,

I have a lisp I use for tagging. It creates a layer, inserts a multileader and puts the layer back when done.

In AcadLT 2025 it creates the layer, does the multileader and then puts the multileader back to the orig layer and puts layer back to original.

 

I'm baffled on whey this is happening. My other lisps that make layer/insert block/put layer back seem to work fine.

I'm hoping this is not big deal and has a simple fix. 

 

Thank you in advance for any assistance.

 

0 Likes
Accepted solutions (1)
1,260 Views
14 Replies
Replies (14)
Message 2 of 15

Moshe-A
Mentor
Mentor

@DC-MWA  hi,

 

check this corrections, untested.

 

Moshe

 

 

(defun c:stag (/ newlayer dscl landist bfind1 bfind2)
 (setvar "cmdecho" 0)
 (setvar "orthomode" 0)
 (setvar "osmode" 512)
 (setvar "attreq" 1)
 (setvar "attdia" 0)
  
;| No need to insert block all the way if only the block
   definition is needed

(setq bfind1 (tblsearch "block" "DC-TAG"))
 (if bfind1 
  (princ "\nDC-TAG found...")
  (progn
   (command "-insert" "DC-TAG" "0,0,0" "" "" "" "1")
   (entdel (entlast))
  );pr
 );if |;

 ; instead cancel command function immediately after supplying block name
  
 (if (null (tblsearch "block" "dc-tag"))
  (progn
   (command "-insert" "dc-tag")
   (command)
  ); progn
 ); if

;| (setq bfind2 (tblsearch "block" "DC-TAGLEADERSTYLES"))
 (if bfind2 
  (princ "\nDC-TAGLEADERSTYLES found...\n")
  (progn
   (command "-insert" "DC-TAGLEADERSTYLES" "0,0,0" "" "" "" "1")
   (entdel (entlast))
  );pr
 );if |;

 (if (null (tblsearch "block" "dc-tag"))
  (progn
   (command "-insert" "dc-tagleaderstyles")
   (command)
  ); progn
 ); if

 ;(DO_KNOTE_LAYER)
 (setq olayer (getvar "clayer")) ;save layer
 (command "layer" "m" "test" "c" "red" "" "")
 (setvar "cmleaderstyle" "dc-tags")
 (setvar "mleaderscale" (getvar "dimscale"))
 (prompt "\nPOINT AT?")
 (setq dscl (getvar "dimscale"))
 (setq landist (* dscl 0.08))
 (command "_.mleader" "_Options" "_Content type" "_Block" "dc-tag" "_leader lAnding" "_yes" landist "eXit Options")
 (prompt "\nPick Tag location...")
  
 (while (/= (getvar "cmdecho") 0)
  (command pause)
 )
  
 (setvar "attdia" 1)
 (setvar "clayer" olayer) ;return to previous layer
 (setvar "cmdecho" 1)
);end c:stag
0 Likes
Message 3 of 15

DC-MWA
Collaborator
Collaborator

error, see below.

DCMWA_0-1722707781584.png

 

0 Likes
Message 4 of 15

DC-MWA
Collaborator
Collaborator

Also,

This:

(while (/= (getvar "cmdecho") 0)
  (command pause)
 )

triggers the dialog entry which requires an additional mouse click. No good.

 

0 Likes
Message 5 of 15

Moshe-A
Mentor
Mentor

As I said I did not test it cause you did not post your blocks

 

Instead cmdecho change it to cmdactive (sorry my mistake)

0 Likes
Message 6 of 15

DC-MWA
Collaborator
Collaborator

See attached...

The issue is that it does not store and put the layer back when done.

It places the mleader on the current layer, not the layer created?

0 Likes
Message 7 of 15

ec-cad
Collaborator
Collaborator

Took the liberty of changing posted code. Hope you don't mind..

(defun c:stag (/ newlayer dscl landist bfind1 bfind2)
 (setvar "cmdecho" 0)
 (setvar "orthomode" 0)
 (setvar "osmode" 512)
 (setvar "attreq" 1)
 (setvar "attdia" 0)
  
;| No need to insert block all the way if only the block
   definition is needed

(setq bfind1 (tblsearch "block" "DC-TAG"))
 (if bfind1 
  (princ "\nDC-TAG found...")
  (progn
   (command "-insert" "DC-TAG" "0,0,0" "" "" "" "1")
   (entdel (entlast))
  );pr
 );if |;

 ; instead cancel command function immediately after supplying block name
  
 (if (null (tblsearch "block" "dc-tag"))
  (progn
   (command "-insert" "dc-tag")
   (command)
  ); progn
 ); if

;| (setq bfind2 (tblsearch "block" "DC-TAGLEADERSTYLES"))
 (if bfind2 
  (princ "\nDC-TAGLEADERSTYLES found...\n")
  (progn
   (command "-insert" "DC-TAGLEADERSTYLES" "0,0,0" "" "" "" "1")
   (entdel (entlast))
  );pr
 );if |;

 (if (null (tblsearch "block" "dc-tag"))
  (progn
   (command "-insert" "dc-tagleaderstyles")
   (command)
  ); progn
 ); if

 ;(DO_KNOTE_LAYER)
 (setq olayer (getvar "clayer")) ;save layer
 (command "layer" "m" "test" "c" "red" "" "")
 (setvar "clayer" "test"); assure we are at layer 'test' <----- added
 (setvar "cmleaderstyle" "dc-tags")
 (setvar "mleaderscale" (getvar "dimscale"))
 (prompt "\nPOINT AT?")
 (setq dscl (getvar "dimscale"))
 (setq landist (* dscl 0.08))
 (command "_.mleader" "_Options" "_Content type" "_Block" "dc-tag" "_leader lAnding" "_yes" landist "eXit Options")
 (prompt "\nPick Tag location...")
  
 (while (/= (getvar "cmdactive") 0); <------ changed
  (command pause)
 )
  
 (setvar "attdia" 1)
 (setvar "clayer" olayer) ;return to previous layer
 (setvar "cmdecho" 1)
);end c:stag

 

ECCAD

0 Likes
Message 8 of 15

DC-MWA
Collaborator
Collaborator

I appreciate the input. None of this seems to help.

I have many other programs that store current layer, do task, put layer back without issue.

I'm guessing it has something to do with the mleader function. Maybe it's changed in 2025??

0 Likes
Message 9 of 15

komondormrex
Mentor
Mentor

hey there,

(initcommandversion) at 31 will definitely do the thing

 

(defun c:stag (/ newlayer dscl landist bfind1 bfind2)
	(setvar "cmdecho" 0)
    (setvar "orthomode" 0)
	(setvar "osmode" 512)
	(setvar"ATTREQ" 1)
    (setvar "ATTDIA" 0)
	(setq bfind1 (tblsearch "block" "DC-TAG"))
	(if bfind1 
		(princ "\nDC-TAG found...")
		(progn
			(command "-insert" "DC-TAG" "0,0,0" "" "" "" "1")
			(entdel (entlast))
		);pr
	);if
	(setq bfind2 (tblsearch "block" "DC-TAGLEADERSTYLES"))
	(if bfind2 
		(princ "\nDC-TAGLEADERSTYLES found...\n")
		(progn
			(command "-insert" "DC-TAGLEADERSTYLES" "0,0,0" "" "" "" "1")
			(entdel (entlast))
		);pr
	);if
	;(DO_KNOTE_LAYER)
	(setq olayer (getvar 'clayer)) ;save layer
	(command "layer" "m" "test" "c" "red" "" "")
	(setvar "cmleaderstyle" "DC-tags")
	(setvar "mleaderscale" (getvar "dimscale"))
	(prompt "\nPOINT AT?")
	(setq dscl (getvar "dimscale"))
	(setq landist (* dscl 0.08))
	(initcommandversion)
	(command "_.mleader" "o" "c" "B" "DC-tag" "a" "yes" landist "x" pause)
    (prompt "\nPick Tag location...")
    (command PAUSE)
    (setvar "ATTDIA" 1)
	(setvar 'clayer olayer) ;return to previous layer
	(setvar "cmdecho" 1)
);end defun c:stag

 

 

0 Likes
Message 10 of 15

DC-MWA
Collaborator
Collaborator

This didn't work. 

0 Likes
Message 11 of 15

pendean
Community Legend
Community Legend

@DC-MWA wrote:

...Maybe it's changed in 2025??


So this/these LISP work in LT2024?

Do you have the LT2025.1 update installed? That seems to have added quite the mess of things (CLayer command related) for some users.

0 Likes
Message 12 of 15

ec-cad
Collaborator
Collaborator

If you 'insert' blocks, they will be on 'current' layer, so when you do a leader, with that block, it will still be on

the current layer..

So, move these (2) lines up near top. Before you insert those blocks.

 

(setq olayer (getvar 'clayer)) ;save layer
	(command "layer" "m" "test" "c" "red" "" "")

 

Also, add the (setvar "clayer" "test").

ECCAD

 

0 Likes
Message 13 of 15

pendean
Community Legend
Community Legend

@ec-cad wrote:

.... Also, add the (setvar "clayer" "test").


@DC-MWA This actually works instead of the otherwise excellent tip in LT2025.1 (CLAYER issues abound there)

pendean_0-1723054170207.png

 

So it looks like you need to stay away from CLAYER in LT2025.1 until the next update out to fix it from Autodesk is available. Next step, change this (aka don't use CLAYER)

pendean_1-1723054237840.png

 

or roll back to LT2024, even with it's latest updates, your original LISP works just fine there.

0 Likes
Message 14 of 15

pkenewell6347
Advocate
Advocate
Accepted solution

The problem is not with CLAYER, it is with the mleader command exiting cleanly on Attributes. Your current solution works because it forces the command execution to be completed before the code continues. Consider this example change to your code; it works because the mleader command exits cleanly before the code continues.

 

(defun c:stag (/ newlayer olayer dscl landist bfind1 bfind2 p1 p2 cn)
   (setvar "cmdecho" 0)
   (setvar "orthomode" 0)
   (setvar "osmode" 512)
   (setvar"ATTREQ" 1)
   (setvar "ATTDIA" 0)
   (setq bfind1 (tblsearch "block" "DC-TAG"))
   (if bfind1
      (princ "\nDC-TAG found...")
      (progn
         (command "-insert" "DC-TAG" "0,0,0" "" "" "" "1")
         (entdel (entlast))
      );pr
   );if
   (setq bfind2 (tblsearch "block" "DC-TAGLEADERSTYLES"))
   (if bfind2
      (princ "\nDC-TAGLEADERSTYLES found...\n")
      (progn
         (command "-insert" "DC-TAGLEADERSTYLES" "0,0,0" "" "" "" "1")
         (entdel (entlast))
      );pr
   );if
   ;(DO_KNOTE_LAYER)
   (setq olayer (getvar "clayer")) ;save layer
   (command "layer" "m" "test" "c" "red" "" "")
   (setvar "cmleaderstyle" "DC-tags")
   (setvar "mleaderscale" (getvar "dimscale"))
   (setq dscl (getvar "dimscale"))
   (setq landist (* dscl 0.08))
   (setq p1 (getpoint "\nSelect Starting Point: ")
            p2 (getpoint p1 "\nPick Tag Location: ")
            cn (getstring "\nEnter TagNumber: ")
   )
   (initcommandversion)
   (command "_.mleader" "o" "c" "B" "DC-tag" "a" "yes" landist "x" p1 p2 cn)
   (setvar "clayer" olayer) ;return to previous layer
   (setvar "ATTDIA" 1)
   (setvar "cmdecho" 1)
);end defun c:stag
0 Likes
Message 15 of 15

DC-MWA
Collaborator
Collaborator

This is what I needed.

I ended up using the following:

 

(initcommandversion)
(prompt "\nPOINT AT?")
(command "_.mleader" "o" "c" "B" "DC-tag" "a" "yes" landist "x" pause)
(prompt "\nPick Tag location...")
(command PAUSE (getstring "\nEnter Tag Number: "))

 

Thank you very much for your assistance!!!

0 Likes