CAD software discussion forum > CAD Tutorial & Tips > how to copy objects from one layer to another in autocad

how to copy objects from one layer to another in autocad

Rank: 1

davies65

Newbie

posts: 6

Registered: 2012-7-11

Message 1 of 2

 how to copy objects from one layer to another in autocad
11-07-2012 05:38 . pm | View his/her posts only
how to use zwcad/ autocad copy object from one layer to another. I did a quick search over the net to find a lisp to move all objects from one layer to another (both existing in the drawing) typing them or by dcl... and it needs to include nested objects (objects inside blocks) because I am trying to move objects from another company's layers to our layers, but it's much difficult than I thought because those objects are nested in very complicated blocks that we are not willing to explode yet, at least not for this task..

Anyone who knows has heard about a lisp like this or has used?

Rank: 1

skyface

Newbie

posts: 9

Registered: 2012-7-6

Message 2 of 2

11-07-2012 05:43 . pm | View his/her posts only
I've never had any problems with LayMrg, but this should do the trick...



Code:
(defun c:Merger (/ ent layer ent2 layer2 i ss ent)
(vl-load-com)

(cond ((and (setq ent (car (nentsel "\nSelect Object on Layer to Merge: ")))
(setq layer (cdr (assoc 8 (entget ent))))
(setq ent2 (car (entsel "\nSelect Object on Layer to Merge to: ")))
(setq layer2 (cdr (assoc 8 (entget ent2))))
(or (not (eq layer layer2)) (alert "Cannot merge layer with itself!"))
) ;_ and
(setq i -1
ss (ssget "_X" (list (cons 8 layer)))
) ;_ setq
(while (setq ent (ssname ss (setq i (1+ i))))
(vla-put-layer (vlax-ename->vla-object ent) layer2)
) ;_ while
(vlax-for blks (vla-get-Blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
) ;_ vla-get-ActiveDocument
) ;_ vla-get-Blocks
(vlax-for obj blks
(if (eq (strcase layer) (strcase (vla-get-layer obj)))
(vla-put-layer obj layer2)
) ;_ if
) ;_ vlax-for
) ;_ vlax-for
)
) ;_ cond
(princ)
) ;_ defun
See also