Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

LISP to use specific layers for commands

FMM_MK
Enthusiast

LISP to use specific layers for commands

FMM_MK
Enthusiast
Enthusiast

Hello guys and greetings from germany,

 

I don't know anything about creating LISPs for AutoCAD - but I'm looking for some to change the current layer (after executing a command) to a specific one and then swicht back to the current.

 

I need this for the following commands:

 

Current layer = 0 - command "_mtext" with layer = text - switch layer back to current layer after executing the command

Current layer = 0 - command "_text" with layer = text - switch layer back to current layer after executing the command

Current layer = 0 - command "_mleader" with layer = mleader - switch layer back to current layer after executing the command

Current layer = 0 - command "_insert" with layer = block - switch layer back to current layer after executing the command

 

I already know how to do this with the tool palette - but I don't want to work with it, cause I'm using the toolbars.

 

Hope you guys can help me!

 

Thank you for your help in advance!

0 Likes
Reply
Accepted solutions (1)
5,469 Views
20 Replies
Replies (20)

Sea-Haven
Mentor
Mentor

Like Kent's answer keeping it simple you could do like B1, B2, so draw a certain beam 1 on layer1, Beam2 on layer2.

 

The other way in more complicated code is using a simple (setvar 'clayer "Beam2") before drawing objects. So the beam has objects on different layers. 

 

As suggested also check does layer exist. So use a small global defun.

 

 

 

(defun chklay (lay COL LT / )
(if (= (tblsearch "layers" lay) nil)
  (command "-layer" "M" lay "C" col "" "LT" lt "" "")
  (setvar 'clayer lay)
)
(princ)
)


(chklay "Beam2" 1 "Continuous")

 

 

 

 

0 Likes