Jump to content

LISP set current layer


demes

Recommended Posts

I was wondering if someone could help me out with this idea.

 

I have for example 3 layers, layer '0', layer '1' and layer '2'

 

I want to creat a simple command that changes the current layer I'm working in. For instance if I just type '2' that my current layer is automatically set to layer '2'.

 

Since I'm always working on only 3 or 4 layers, this would make changing between them quite easy...

 

I don't want one single command to automatically recognize the name of the layer, I would make 4 commands for the 4 different layers.

 

ANY SUGGESTIONS?

thanks!

Link to comment
Share on other sites

(defun _SetCLayer (layerName)
 (if (tblsearch "layer" layerName)
   (setvar 'clayer layerName)
   (prompt
     (strcat "\n** Layer \"" layerName "\" not found ** ")
   )
 )
 (princ)
)

(defun c:0 () (_SetCLayer "0"))
(defun c:1 () (_SetCLayer "1"))
(defun c:2 () (_SetCLayer "2"))
(defun c:3 () (_SetCLayer "3"))

Link to comment
Share on other sites

Hi BlackBox!

thanks for you quick response...

I've the feeling that your code is exactly what I need, but I'm completely new with autocad codes so I was wondering If you could tell me for 1 of the 4 examples how exactly I have to put it into my user interface...

I tried some things but none of them seems to be able to recognise the command (I tried it for layer 0)

Link to comment
Share on other sites

As Dave pointed out if you are using LT, lisp code will not run in it. You'll have to resort to using a macro.

 

The command line version of the layer command (-Layer) has an option called Set. That's how you could do it.

 

This macro would set layer 1 current.

 

^C^C-Layer;Set;1;;

 

Macros can be assigned to buttons.

 

If your profile is incorrect re "LT" could you please change it? Thanks.

Edited by ReMark
Link to comment
Share on other sites

thanks ReMark,

is it possible to run the macro once it is installed from the command line, or can I only run it when I assign a button to it?

Link to comment
Share on other sites

I'd assign it to a button and place the button on a custom toolbar.

 

Have you thought of just using the Make Object's Layer Current button?

Link to comment
Share on other sites

Sorry demes, I rarely check what someone is using when they specifically ask for help with LISP, and I should have.

 

As DBroada, and ReMark have made clear, you're relegated to using macros/scripts in LT, so for this situation, I'd follow ReMarks advise here:

 

Have you thought of just using the Make Object's Layer Current button?

Link to comment
Share on other sites

here is a toolbar for you but you need to make your own icons called 0lay etc

 

1m.jpg

 

***MENUGROUP=layers
***TOOLBARS
**Layers
ID_ALAN    [_Toolbar("Layers", _LEFT, _Show, 0,0, 1)]
0 lay[_Button("0lay","0lay.BMP","0lay.BMP")]^c^c^c(layer s "0")
1 lay[_Button("1lay","1lay.BMP","1lay.BMP")]^c^c^c(layer s "1")

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...