TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: scott.nance on October 17, 2018, 05:50:39 PM

Title: Copying an object to every layer
Post by: scott.nance 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!
Title: Re: Copying an object to every layer
Post by: Lee Mac 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. )
Title: Re: Copying an object to every layer
Post by: scott.nance on October 18, 2018, 10:15:16 AM
Thanks Lee! Works perfect.