Jump to content

Transfer all objects from one layer to another


gilsoto13

Recommended Posts

Hi, Everyone

 

I did a quick search over the net to find a lisp to transfer 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?

Link to comment
Share on other sites

Hey Lee...

 

It seems I get some trouble with specific layers using "laymrg" from autocad...

But this lisp you made works great, how difficult will it be to modify it to merge one picked object's layer's object into another picked object's layer...

you know... exactly as "laymrg" but modifying your lisp... I just thought about entdel by something to change entities' layer property...

 

and instead vla-delete... vla-put- (something)

 

 
(defun c:DeleteAll (/ ent layer i ss ent)
 (vl-load-com)
 
 (cond (  (setq ent (car (nentsel "\nSelect Object on Layer to Delete: ")))
          (setq layer (cdr (assoc 8 (entget ent))))
          (setq i -1 ss (ssget "_X" (list (cons 8 layer))))
          (while (setq ent (ssname ss (setq i (1+ i)))) (entdel ent))
          (vlax-for blks (vla-get-Blocks
                           (vla-get-ActiveDocument
                             (vlax-get-acad-object)))
            (vlax-for obj blks
              (if (eq (strcase layer) (strcase (vla-get-layer obj)))
                (vla-delete obj))))))
 (princ))

Link to comment
Share on other sites

I've never had any problems with LayMrg, but this should do the trick...

 

(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

Link to comment
Share on other sites

I've never had any problems with LayMrg, but this should do the trick...

 

(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

 

 

and voalá... incredible...

 

laymrg for some cases does not do anything, doesn´t give any error or message but also there's no change with those layers... so I am not in the office right now but I'll check it out with the same drawing next monday.... right now it worked perfect in another drawing. Thank you very much, I gotta say that I didn´t know about laymrg until yesterday and it could have been very useful a year ago... but now it's more useful and it's great now that I've got another option in case the command doesn´t work...

 

I was almost done with the drawing, I used laymrg about 40 times, also used the MergetextStyles.lsp by CAB (I think) and also used a lot refedit and CCO.lsp (to change adjusted color entities to bylayer to a layer named as the color) and also used a lot the bl0.lsp (to fix blocks to layer 0 and color bylayer)

 

I fixed a big drawing (a Mine layout) from another company into our standards in just one day)...

Link to comment
Share on other sites

Have you tried LAYTRANS?

 

It will achieve the same as laymrg but with greater flexibility.

 

It allows you to map multiple layers in the current drawing, to those specified in another via a dialog

 

Check out the AutoCad User documentation for further info

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...