Macro: CLAYER+LAYCUR

Macro: CLAYER+LAYCUR

M.Lindell
Enthusiast Enthusiast
1,750 Views
7 Replies
Message 1 of 8

Macro: CLAYER+LAYCUR

M.Lindell
Enthusiast
Enthusiast

Hello,
I have made quick buttons for my favourite layers. (faster than scrolling the full list of layers)
   -Macro: CLAYER "Layer name here"
I would like it to also change the layer of a selected object.

So I want to combine CLAYER and LAYCUR.
I always lose the selection after CLAYER-command and I can't select PREVIOUS for LAYCUR because it would change the previous modified object even if I have nothing selected.

Little help would be appreciated 🙂

0 Likes
Accepted solutions (1)
1,751 Views
7 Replies
Replies (7)
Message 2 of 8

pendean
Community Legend
Community Legend
0 Likes
Message 3 of 8

CodeDing
Advisor
Advisor
Accepted solution

@M.Lindell ,

 

I'm no expert with macros, but I believe this is what you're looking for. Try this as your macro (update your layer name):

 

 

(progn (setq ss (ssget "_I")) (setvar 'CLAYER "Layer Name Here") (if ss (command "_.LAYCUR" ss "") (command "_.LAYCUR" pause)) (setq ss nil) (princ))

 

 

 

Best,

~DD

Message 4 of 8

ВeekeeCZ
Consultant
Consultant

Since the only purpose of setting your layer current is to serve to the LAYCUR command... Don't you rather want to just CHANGE a layer of preselected/selected objects to some of your predefined layers? Leaving the layer Current might be confusing.

 

BTW Are you on LT?

0 Likes
Message 5 of 8

ВeekeeCZ
Consultant
Consultant

@ВeekeeCZ wrote:

Since the only purpose of setting your layer current is to serve to the LAYCUR command... Don't you rather want to just CHANGE a layer of preselected/selected objects to some of your predefined layers? Leaving the layer Current might be confusing.

 

BTW Are you on LT?


 

If you not on LT here's the lisp/macro for you button to just change the layer.

 

((lambda (/ s) (if (setq s (ssget "_:L")) (command "_.chprop" s "" "_la" "_kom_1_hrany" "")) (princ)))
0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

Maybe you can use variants of this routine:

(defun C:L0 ()
  ; put pre-selected object(s) [if any] on Layer 0, otherwise set current Layer to 0
  (if (ssget "_I")
    (command "_.chprop" "_layer" "0" ""); then
    (command "_.layer" "_thaw" "0" "_set" "0" ""); else
  ); if
  (princ)
)

If there are any pre-selected objects, it puts them on Layer 0 [you can substitute a different Layer name, and make such a command for any Layer(s) you need].  If there are no pre-selected objects, it sets Layer 0 current.  [It does not account for possible locked Layers, but they would not cause an error -- they just won't be changed.]

 

Or, maybe you can use something like this, which is to put things on the current Layer:

;| ToCurrentLayer.lsp [command name: TCL]
  Moves selected objects to current layer.
  Kent Cooper, last edited 29 Jan 2021 to allow pre-selection
|;
(defun C:TCL (); = To Current Layer
  (command "_.chprop"
    (cond
      ((ssget "_I") (ssget "_:L-I")); unlocked only among pre-selection if any
      ((ssget "_:L")); otherwise, unlocked only among new selection
    ); cond
    "" "_layer" (getvar 'clayer) ""
  ); command
  (princ)
); defun

If there are any pre-selected objects, it moves them [any of them not on locked Layers, that is] to the current Layer.  If not, it asks the User to select objects [again forbidding those on locked Layers], and moves them to the current Layer.

 

But I agree with the question -- is the only reason for changing the current Layer to move things to it?  It's not necessary to do it that way, but you can just put things on that Layer without making it current, as the L0 command above does if there's a pre-selection.

Kent Cooper, AIA
Message 7 of 8

M.Lindell
Enthusiast
Enthusiast
Thank you very much!
I added ;^C^C at the end and now it works just as I wanted.

I'm no expert either with macros and couldn't have been able to figure that one out without your help.
0 Likes
Message 8 of 8

M.Lindell
Enthusiast
Enthusiast

Thank you for responding. The first routine is really good alternative but I think the one @CodeDing shared works better for me (;^C^C added at the end).

 "is the only reason for changing the current Layer to move things to it?"
  -No. For me the primary function of this macro is to change layers among my "favourites" but often I have noticed that I need need to take some object to that new layer at the same time.

0 Likes