selected objects to new layer

selected objects to new layer

jyan2000
Advocate Advocate
1,095 Views
3 Replies
Message 1 of 4

selected objects to new layer

jyan2000
Advocate
Advocate

Hello everyone,

 

anyone could help me to make a lisp to change selected objects to new layer?  (as shown in dwg file)

 

Regards

Victor

0 Likes
1,096 Views
3 Replies
Replies (3)
Message 2 of 4

john.uhden
Mentor
Mentor

Quick (no error or undo)

 

(defun c:C2NL ( / ss layer)
  (and
    (princ "\nSelect objects to change to new layer: ")
    (setq ss (ssget))
    (setq layer (getstring "\nNew layer name: "))
    (or
      (snvalid layer)
      (prompt "\nInvalid layer name.")
    )
    (vl-cmdf "_.-layer" "_M" layer "")
    (vl-cmdf "_.chprop" ss "" "_La" layer "")
  )
  (princ)
)

John F. Uhden

0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant

About the "including blocks" part....

 

Your sample drawing contains two Blocks [with wacky PasteBlock names] that are the same except for the Layer(s) of the objects nested in them.  The one with multiple non-0 Layers represented in its parts is inserted on Layer 0, which is all you would get from @john.uhden's suggestion -- it wouldn't change the pieces inside the Block definition.

 

Obviously for sample purposes in the same drawing you need those to be different Block names.  But is it your intent that a Block like that, among the selected objects, should be redefined, so that all its pieces, as well as its insertion, are on Layer 0, thus affecting all insertions of that Block in the drawing?  Or should it be made into a new Block with a different name as in your sample, so that other insertions of it that were not selected can remain as they are, with the original definition and the original Layers of the nested objects?  Would it be acceptable to just Explode all selected Blocks and put all the resulting pieces on Layer 0, rather than have them in Blocks in the end result?

Kent Cooper, AIA
0 Likes
Message 4 of 4

jyan2000
Advocate
Advocate

Hello Kent Cooper and John Uhden,

 

and Thanks to you John Uhden for your quick reply. John Uhden's code works well.

- Blocks move to new layer but everything inside the blocks also must move to under new layer name or Layer 0.

- It doesnt has to be new block name.

- Insertion point can remain as it is. 

- blocks can explode and put in one layer. (that was the intention else John Uhden's code good enough)

 

Why i need this lisp is, its really hard to control certain objects in a huge drawings. I just want to put some objects to new Named layer/s. So i can easily Freeze / off others and work on those new layer/s. 

 

Best regars

Victor

 

0 Likes