Author Topic: Copy all objects to other layer  (Read 2386 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Copy all objects to other layer
« on: January 21, 2008, 07:13:05 PM »
Hi,
it's my code to copy all objects in layer "0" to layer "Temp", but it's still got problem, the result all objects still in layer 0.
Code: [Select]
(defun c:test (/ cnt lay nlay pt ss sse ssl ssn)
  (setq nlay "TEMP")
  (setq lay (getvar "clayer"))
  (if
    (/= lay nlay)
    (command "_layer" "m" nlay "c" 7 "" "")
    )
  (setvar "clayer" "0")
  (command "_layer" "off" nlay "")
  (setq ss (ssget "x" '((8 . "0"))))
  (setq ssl (sslength ss))
  (setq cnt 0)
  (repeat
    ssl
    (setq ssn (ssname ss cnt))
    (setq sse (entget ssn))
    ;(setq etyp (cdr (assoc 0 sse)))
    (setq pt (cdr (assoc 10 sse)))
    (setvar "clayer" nlay)
    (command "_copy" ssn "" pt pt "")
    (setq cnt (1+ cnt))
    ) ; repeat
  (princ)
  )   ; defun
« Last Edit: January 22, 2008, 11:50:44 AM by Daron »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Copy alls object to other layer
« Reply #1 on: January 21, 2008, 08:49:34 PM »
Do you want two of every object in the drawing or just set all objects to layer "0"?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Copy alls object to other layer
« Reply #2 on: January 21, 2008, 08:56:57 PM »
Give this a try :)
Code: [Select]
(defun c:test (/ cnt lay nlay pt ss sse ssl ssn)
  (vl-load-com)
  (setq nlay "TEMP")
  (setq lay (getvar "clayer"))
  (if
    (/= lay nlay)
     (command "_layer" "m" nlay "c" 7 "" "")
  )
  (setvar "clayer" "0")
  (command "_layer" "off" nlay "")
  (setq ss (ssget "x" '((8 . "0"))))
  (setq ssl (sslength ss))
  (setq cnt 0)
  (repeat
    ssl
     (setq ssn (ssname ss cnt))
     (setq sse (entget ssn))
;(setq etyp (cdr (assoc 0 sse)))
     (setq pt (cdr (assoc 10 sse)))
     (setvar "clayer" nlay)
     (command "_copy" ssn "" pt pt "")
     (vla-put-layer (vlax-ename->vla-object (entlast)) "TEMP")
     (setq cnt (1+ cnt))
  ) ; repeat
  (princ)
) ; defun

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Adesu

  • Guest
Re: Copy alls object to other layer
« Reply #3 on: January 21, 2008, 09:50:09 PM »
Hi ronjonp,
Wow......it's great...thanks.

FengK

  • Guest
Re: Copy alls object to other layer
« Reply #4 on: January 22, 2008, 12:49:49 AM »
Not tested.

(defun c:test (/ doc colLay layName ss i obj)
  (setq doc (vla-get-activedocument (vlax-get-acad-object))
        colLa (vla-get-layers doc)
        layName "Temp")
  (if (not (tblsearch "LAYER" layName))
    (vla-add colLay layName)
  )
  (if (setq ss (ssget "X" (list (cons 8 "0"))))
    (progn
      (setq i 0)
      (repeat (sslength ss)
        (setq obj (vla-copy (vlax-ename->vla-object (ssname ss i))))
        (vla-put-layer obj layName)
        (setq i (1+ i))
      )
      (prompt "\nDone.")
    )
    (prompt "\nNo object on layer \"0\"".))
  (princ)
)

Adesu

  • Guest
Re: Copy alls object to other layer
« Reply #5 on: January 22, 2008, 01:15:59 AM »
Hi Kelie,
it's great too....thanks

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Copy alls object to other layer
« Reply #6 on: January 22, 2008, 10:25:21 AM »
Hi ronjonp,
Wow......it's great...thanks.

:)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

FengK

  • Guest
Re: Copy alls object to other layer
« Reply #7 on: January 22, 2008, 11:37:28 AM »
Hi Kelie,
it's great too....thanks

You're welcome.