Author Topic: Copying an object to every layer  (Read 1500 times)

0 Members and 1 Guest are viewing this topic.

scott.nance

  • Mosquito
  • Posts: 6
Copying an object to every layer
« on: October 17, 2018, 05:50:39 PM »
Hi all,

I would like to copy a selected object to every layer existing in a drawing. I tried everything I could think of using the copytolayer command but nothing would allow me to copy it to multiple layers at once. I did find some helpful routines that allowed you to select multiple layers but was hoping it would copy to all layers without needing to make decisions past executing the command.

Thanks!

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Copying an object to every layer
« Reply #1 on: October 17, 2018, 06:29:40 PM »
Quick n dirty -
Code - Auto/Visual Lisp: [Select]
  1. (defun c:c2a ( / idx lst lyn sel )
  2.     (if (setq sel (ssget "_:L"))
  3.         (progn
  4.             (repeat (setq idx (sslength sel))
  5.                 (setq idx (1- idx)
  6.                       lst (cons (vlax-ename->vla-object (ssname sel idx)) lst)
  7.                 )
  8.             )
  9.             (while (setq lay (tblnext "layer" (not lay)))
  10.                 (if (wcmatch (setq lyn (cdr (assoc 2 lay))) "~*|*")
  11.                     (foreach obj lst
  12.                         (if (/= lyn (vla-get-layer obj))
  13.                             (vla-put-layer (vla-copy obj) lyn)
  14.                         )
  15.                     )
  16.                 )
  17.             )
  18.         )
  19.     )
  20.     (princ)
  21. )

scott.nance

  • Mosquito
  • Posts: 6
Re: Copying an object to every layer
« Reply #2 on: October 18, 2018, 10:15:16 AM »
Thanks Lee! Works perfect.