Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy a block to all layers

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
kameron1967
603 Views, 14 Replies

Copy a block to all layers

Hi guys,

 

If I have BLOCKA on a layer (or specifically layer 0), how do you copy blockA onto every layers?  I'm sure there are 5 ways of doing this.  Thanks in advance! 🙂

14 REPLIES 14
Message 2 of 15
pbejse
in reply to: kameron1967


@kameron1967 wrote:

Hi guys,

 

If I have BLOCKA on a layer (or specifically layer 0), how do you copy blockA onto every layers?  I'm sure there are 5 ways of doing this.  Thanks in advance! 🙂


And what of the location? on the same spot? one on top of the other?

 

Message 3 of 15
pbejse
in reply to: pbejse

Sample

 

(defun c:CB2Layer ( / blk clay e lay a)
  (if (setq blk (ssget "_:S:E:L" '((0 . "INSERT"))))
    (progn
      (setq clay (cdr (assoc 8 (entget (setq e (ssname blk 0)))))
            e    (vlax-ename->vla-object e)
      )
      (while (setq a (tblnext "Layer" (null a)))
        (if
          (not (member (setq lay (Cdr (assoc 2 a))) (list clay "Defpoints")));<-- exclusion list
           (vla-put-layer (vla-copy e) lay)
        )
      )
    )(princ "\nNo Block selected:")
  )(princ)
)
(vl-load-com)

 

Message 4 of 15
kameron1967
in reply to: pbejse

Pbejse - yes, same location at 0,0,0. Good question.
Message 5 of 15
kameron1967
in reply to: pbejse

I tested it and it worked, pbejse!  I found a way to specify the block name, without it asking, so thanks again.  Your expertise is much appreciated! 🙂 

Message 6 of 15
pbejse
in reply to: kameron1967


@kameron1967 wrote:

I tested it and it worked, pbejse!  


Glad you it sorted, Happy to help.

 

Cheers kameron1967

Message 7 of 15
kameron1967
in reply to: pbejse

Pbejse – if I wanted to explode these blocks and have the broken entities reside on whatever layer(s) they’ve been copied to, how do I do that? I tried inserting the burst command but it does not like it for some reason. Thanks.
Message 8 of 15
mid-awe
in reply to: kameron1967

It seems much more sensible to make the block reside on a layer for it and make that layer visible at all times. jmo
Message 9 of 15
pbejse
in reply to: kameron1967


@kameron1967 wrote:
Pbejse – if I wanted to explode these blocks and have the broken entities reside on whatever layer(s) they’ve been copied to, how do I do that? 

Yes, it can be done. But what of the block? is there no need to keep the "copied" block?

 

Message 10 of 15
kameron1967
in reply to: pbejse

The block will simply be exploded and only the remaining content is kept on their respective layers. Assume that the entire content in that block is on layer 0. Once it's copied to other layers, it will simply be bursted versus exploded, so that the contents within those copied blocks remain on their respective layers. Hope that makes sense. Thanks again, Pbejse. 🙂
Message 11 of 15
pbejse
in reply to: kameron1967


@kameron1967 wrote:
The block will simply be exploded and only the remaining content is kept on their respective layers. Assume that the entire content in that block is on layer 0. Once it's copied to other layers, it will simply be bursted versus exploded, so that the contents within those copied blocks remain on their respective layers. Hope that makes sense. Thanks again, Pbejse. 🙂

I see, for a while there, i thought the reason for the burst is because the block has attributes. if thats not the case we can make do without using burst. or is there attributes on some of your blocks? i remember you are targeting a specific block correct?

 

Message 12 of 15
kameron1967
in reply to: pbejse

There are no attributes on this block. It is, however, a 3D solid object which has been put into BLOCKX.DWG. Not sure if that would affect your routine or not..
Message 13 of 15
pbejse
in reply to: kameron1967


@kameron1967 wrote:
There are no attributes on this block. It is, however, a 3D solid object which has been put into BLOCKX.DWG. Not sure if that would affect your routine or not..

Try this

 

(defun c:CB2LayerX (/ blk clay e lay a ExColl)
  (if (setq blk (ssget "_:S:E:L" '((0 . "INSERT"))))
    (progn
      (setq clay (cdr (assoc 8 (entget (setq e (ssname blk 0)))))
            e    (vlax-ename->vla-object e)
      )
      (while (setq a (tblnext "Layer" (null a)))
        (if
          (not (member
                 (setq lay (Cdr (assoc 2 a))) (list clay "Defpoints")));<-- exclusion list
          	(progn
                  	(setq ExColl (vlax-invoke e 'Explode))
                  	(mapcar '(lambda (j)
                                   (Vla-put-layer j lay)) ExColl))
          
        )
      )
    )
    (princ "\nNo Block selected:")
  )
  (princ)
)
(vl-load-com)

 

command: CB2LAYERX 

Message 14 of 15
kameron1967
in reply to: pbejse

You've got it, Pbejse! That worked without any glitches. Thanks for the awesome support - you rock! 🙂
Message 15 of 15
pbejse
in reply to: kameron1967


@kameron1967 wrote:
You've got it, Pbejse! That worked without any glitches. Thanks for the awesome support - you rock! 🙂

Excellent, 

 

Glad to be of service 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost