Change layer(s) in a block to blocklayer

Change layer(s) in a block to blocklayer

Sandervp
Advocate Advocate
1,837 Views
9 Replies
Message 1 of 10

Change layer(s) in a block to blocklayer

Sandervp
Advocate
Advocate

Hello everybody,

 

I have got a lot of blocks in a drawing. All those blocks are in the same layer, for example "A".

But those blocks consists of different, multiple layers. Also layer "0" is one of those layers.

 

How can I change all the layers in a block into layer "A"?

 

I can not use the command "LAYMRG" because I can't merge the layer "0". How can I solve this problem?

 

 

Thank you.

 

 

 

Cycling for Cancer

That's what I'm going to do.

June 1st, I'm going to climb the Alpe d'Huez.

Not once, but my target is 4 times.

 

Help me/ the Dutch Cancerfund and look at my action page, any amount is welcome: Alpe d'HuZes

 

Nobody death by cancer..

That's what I want...

You also?

0 Likes
Accepted solutions (1)
1,838 Views
9 Replies
Replies (9)
Message 2 of 10

ВeekeeCZ
Consultant
Consultant

See the example HERE

 

You should make sure that your layer "A" really exists.

 

(or (tblsearch "LAYER" "A")
    (command "_.LAYER" "_N" "A" ""))

... or use the (entmake) if you want. See HERE

0 Likes
Message 3 of 10

Sandervp
Advocate
Advocate

Hello BeekeeCZ,

 

Your sollutions aren't working. 

 

If I use the "setbylayer" command, it changes the color of the layers in a block into "color bylayer". But it doesn't change the layer(s) in the block, into the layer of the block.

 

I've created a drawing with only the blocks of layer A. These blocks consists of layers 0 + x + y + z objects (for example). These layers must change into layer A. So if I purge the drawing, layers x + y + z are removed. And the block doesn't contain any object of layer 0.

 

After this is done, I could use the "setbylayer" command for the colors.

 

Perhaps I was a little bit unclear.

0 Likes
Message 4 of 10

ВeekeeCZ
Consultant
Consultant

Try this modified version...

 

; written by: tom beauford
; mods by beekeecz

(defun c:BLayInAsOut (/ sset intcount enam elst bnam flst fix1 lay)
  
  (defun fix1 (bnam / benam bonam)
    (if (not (member bnam flst))
      (progn
        (setq flst  (cons bnam flst)
              benam (tblobjname "BLOCK" bnam)
              )
        (while (setq benam (entnext benam))
          (if (= (cdr (assoc 0 (entget benam))) "INSERT")
            (fix1 (cdr (assoc 2 (entget benam))))
            (progn
              (setq bonam(vlax-ename->vla-object benam))
              (vl-catch-all-apply 'vla-put-layer (list bonam lay))
              (vl-catch-all-apply 'vla-put-color (list bonam 256))
              (vl-catch-all-apply 'vla-put-linetype (list bonam "bylayer"))
              (vl-catch-all-apply 'vla-put-lineweight (list bonam -1))
              ;                (vl-catch-all-apply 'vla-put-plotstylename (list bonam "bylayer"))
              ))))))
  
  (if (and (setq sset (ssget (list (cons 0 "INSERT"))))
           (vl-cmdf "_.undo" "_begin")
           (setq lay (cdr (assoc 8 (entget (ssname sset 0)))))
           )
    (repeat (setq intcount (sslength sset))
      (setq intcount     (1- intcount)
            enam (ssname sset intcount)
            elst (entget enam)
            bnam (cdr (assoc 2 elst))
            flst nil)
      (fix1 bnam)))
  (vl-cmdf "_.undo" "_end")
  (vl-cmdf "_.regen")
  (princ)
  )
0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@Sandervp wrote:

 

.... 

I've created a drawing with only the blocks of layer A. These blocks consists of layers 0 + x + y + z objects (for example). These layers must change into layer A. So if I purge the drawing, layers x + y + z are removed. And the block doesn't contain any object of layer 0.

 

....

Try BlockToLayer.lsp with its BTL command, that I came up with back in 2008 [it's probably in this Forum somewhere, but I couldn't find it quickly]:

;;;  BlockToLayer.lsp [command name: BTL]
;;;  To convert all entities in a block definition to the Layer on
;;;  which a selected instance of the Block is Inserted and to
;;;  color Bylayer, and to move all instances of that Block to
;;;  that Layer.

(defun C:BTL ()
  (setq
    blk (entsel "\nSelect Block: ")
    blkdata (entget (car blk))
    blklay (cdr (assoc 8 blkdata))
  ); setq
  (command
    "_.-refedit" (cadr blk)
    "_Next" "_Next" "_Next" "_OK"
    "_All" "_No"
    "_.chprop" "_All" "" "_Layer" blklay "_Color" "_Bylayer" ""
    "_.refclose" "_Save"
    "_.chprop"
      (ssget "_X" (list '(0 . "INSERT") (cons 2 (cdr (assoc 2 blkdata))))) ""
      "_Layer" blklay ""
  ); command
); defun
Kent Cooper, AIA
0 Likes
Message 6 of 10

Sandervp
Advocate
Advocate

Hello BeekeeCZ and Kent1Cooper,

 

I've tried both lisp files but they doesn't work.

 

If I use the "BLayInAsOut" command, the blocks still containts layer 0.

 

This is also when I use the "BLT" command. If I use the "BTL" command, I can't select multiple blocks. Only one.

This will take a lot of time if I have to change a lot of blocks.

 

I've attach the drawing with the blocks.

 

0 Likes
Message 7 of 10

ВeekeeCZ
Consultant
Consultant
Accepted solution

Yeah... you're right... I've used this example before... remember this issue. It's easy to fix - hope so 🙂

 

; written by: tom beauford
; mods by beekeecz

(defun c:BLayInAsOut (/ sset intcount enam elst bnam flst fix1 lay)
  
  (defun fix1 (bnam / benam bonam)
    (if (not (member bnam flst))
      (progn
        (setq flst  (cons bnam flst)
              benam (tblobjname "BLOCK" bnam)
              )
        (while (setq benam (entnext benam))
          (if (= (cdr (assoc 0 (entget benam))) "INSERT")
            (fix1 (cdr (assoc 2 (entget benam)))))
          (setq bonam (vlax-ename->vla-object benam))
          (vl-catch-all-apply 'vla-put-layer (list bonam lay))
          (vl-catch-all-apply 'vla-put-color (list bonam 256))
          (vl-catch-all-apply 'vla-put-linetype (list bonam "bylayer"))
          (vl-catch-all-apply 'vla-put-lineweight (list bonam -1))
          ;   (vl-catch-all-apply 'vla-put-plotstylename (list bonam "bylayer"))
          ))))
  
  (if (and (setq sset (ssget (list (cons 0 "INSERT"))))
           (vl-cmdf "_.undo" "_begin")
           (setq lay (cdr (assoc 8 (entget (ssname sset 0)))))
           )
    (repeat (setq intcount (sslength sset))
      (setq intcount     (1- intcount)
            enam (ssname sset intcount)
            elst (entget enam)
            bnam (cdr (assoc 2 elst))
            flst nil)
      (fix1 bnam)))
  (vl-cmdf "_.undo" "_end")
  (vl-cmdf "_.regen")
  (princ)
  )

 

Message 8 of 10

Sandervp
Advocate
Advocate

Thank you (again) BeekeeCZ!

 

This is what I want

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant

@Sandervp wrote:

.... the blocks still containts layer 0.

 

This is also when I use the "BLT" command. .... 


BTL [not BLT] shouldn't leave anything in the Block on Layer 0, and doesn't for me [Acad2016 here] -- all parts are changed to the same Layer as that on which the Block is inserted.  Does it really not do that for you?  Do you perhaps have Layer 0 locked?

 

[And all other Block insertions of that name are also moved to that Layer, but it sounds like they already are in your case.  If your only-one issue is because you have various different Block names involved, at least that means you would only have to run BTL on one insertion of each Block name.]

Kent Cooper, AIA
0 Likes
Message 10 of 10

Sandervp
Advocate
Advocate

Hello Kent1Cooper,

 

I'm using AutoCad 2016 also. Your lisp works if the block doesn't contain other blocks.

Some blocks in my drawing are containing block, in block, in block. If I use your command and I select a block which contains another block, it doesn't work. But if I select a block without another block inside, your lisp works.

 

If I use your lisp, I couldn't select multiple blocks. I have to select a block, use your lisp and do this over and over again.

 

If I use BeekeeCZ his lisp, I can select everything/ multiple blocks. His lisp is also changing the layernames of the blocks inside another blocks.

 

 

 

Try using your lisp if you have a block which contains other blocks with other layernames.

 

 

0 Likes