Copy All Objects From One Layer To New Layer w/o Selecting

Copy All Objects From One Layer To New Layer w/o Selecting

Anonymous
Not applicable
2,491 Views
7 Replies
Message 1 of 8

Copy All Objects From One Layer To New Layer w/o Selecting

Anonymous
Not applicable

Hello Everyone,

 

I was wondering if someone can help me modify the lisp below. I would like to universally copy all objects from the "WB_0" layer to the "WB_MFG_REF" layer without selecting. 

 

Any help is greatly appreciated.

 

Xi

 

;Written by Odie Silva on Feb 6,2002
 ;
 ;CPLAY duplicates selected entities to a specified layer.
 ;
 (defun c:LREF (/ ss lay pt1 pt2)
 (setvar "cmdecho" 0)
 (setq pt1 "0,0,0")
 (setq pt2 "0,0,0")
 (setq verlay (tblsearch "layer" "WB_MFG_REF"))
 (chklay)
 (setq lay "WB_MFG_REF")
 (setq lay (getstring (strcat "\nDestination Layer: " lay "?: ")))
 (if (/= lay "")
 (progn
 (setq verlay (tblsearch "layer" lay))
 (if (= verlay nil)
 (chklay)
 )

 )
 (setq lay "WB_MFG_REF")
 )
 (setq ss (ssget))
 (command "copy" ss "" pt1 pt2)
 (command "change" ss "" "p" "la" lay "")
 (princ)
 )


 (defun chklay ()
 (if (= verlay nil)
 (progn
 (initget "Y N")
 (setq ans
 (strcase
 (getkword
 "\nDefault layer dos not exist. Do you want to create it?: "
 )
 )
 )
 (cond
 ((= ans "Y")
 (setq lay (getstring "\nEnter new layer name: "))
 (setq col (rtos (acad_colordlg 7) 2 0))
 (command "layer" "m" lay "c" col "" "")
 )
 ((= ans "N")
 (princ "\nProgram Exited.")
 (exit)
 )
 )
 )
 (setq lay "WB_MFG_REF")
 )
 )
0 Likes
Accepted solutions (2)
2,492 Views
7 Replies
Replies (7)
Message 2 of 8

SeeMSixty7
Advisor
Advisor
Accepted solution

Try this.

This does the bulk of what you want, but it does not do the Layer Validation. You can use they layer validation function in your posted code and just add it in here.

 

(defun C:CPLAY()
   (setq cplay-ss (ssget "X" '((8 . "WB_0"))))
   (if cplay-ss
       (progn
           (command "copy" cplay-ss "" "0,0,0" "0,0,0" "")
           (command "change" cplay-ss ""  "p" "la" "WB_MFG_REF" "")
       )
   )
)

 

Good luck - Learn more by experimenting!

Message 3 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Never like if the routine changes the original...

 

(defun c:Copy0ToRef ( / ss)

  (if (setq ss (ssget "_A" '((8 . "WB_0"))))
    (progn
      (or (tblsearch "LAYER" "WB_MFG_REF")
          (command "_.LAYER" "_N" "WB_MFG_REF" ""))
      (command "_.-COPYTOLAYER" ss "" "WB_MFG_REF" "_D" "0,0,0")))
  (princ)
)
Message 4 of 8

Anonymous
Not applicable

Wow ! That was fast.   It works wonderfully.

 

Thank you guys !

0 Likes
Message 5 of 8

Anonymous
Not applicable

And I thought that I was done.

How would I modify this lisp if Multiple layers were to be copied?

0 Likes
Message 6 of 8

ВeekeeCZ
Consultant
Consultant
'((8 . "WB_0,WB_1,WB_2"))
...like this. Delimited by a comma.
Message 7 of 8

ariskouros
Participant
Participant

How not to copy again to the layer when you run it for another time?

0 Likes
Message 8 of 8

ВeekeeCZ
Consultant
Consultant

@ariskouros 

 

I have a little trouble understanding what you need. What is your ultimate goal? Maybe add some sample dwg with before and after.

In any case, I would recommend starting a new topic, as you'll get more attention that way.

 

Good luck.

0 Likes