RE) LISP Get entities layer list within blocks and change layer of blocks

RE) LISP Get entities layer list within blocks and change layer of blocks

darkfprh
Advocate Advocate
1,026 Views
5 Replies
Message 1 of 6

RE) LISP Get entities layer list within blocks and change layer of blocks

darkfprh
Advocate
Advocate

Hi

 

I need a lisp that checks all block's inside entities' layer.

and It has more than 2 layers, change block's layer to "0".

 

help me plz.

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-get-entities-layer-list-within-...

0 Likes
Accepted solutions (1)
1,027 Views
5 Replies
Replies (5)
Message 2 of 6

vinodkl
Mentor
Mentor

Hi @darkfprh 

 

Have you tried the FIXBLOCK lisp? See attached.

Also, it would be great if you would stick to a single post instead of creating a new thread. It would create more confusion than solving your problem as people in the forum will ignore to answer the thread if they find it repetitive🙂

--------------------------------------------------------------------------------------------------------------------------
ವಿನೋದ್ ಕೆ ಎಲ್( System Design Engineer)
Likes is much appreciated if the information I have shared is helpful to you and/or others.

Please mark "Accept as Solution" if my reply resolves the issue or answers your question, to help others in the community.
--------------------------------------------------------------------------------------------------------------------------
0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant

@vinodkl wrote:

Have you tried the FIXBLOCK lisp? .... stick to a single post instead of creating a new thread. ....


I don't think FIXBLOCK is what they're after.  It looks like it puts the objects within Block definitions on Layer 0 [and color ByLayer], but they're not talking about changing the Layer of ingredients within Blocks.  They want to change the Layer of Block insertions whose Block-definition ingredients include things on more than 2 Layers.

 

[I agree about double posting, but I think the intent is much more clearly described in this one.]

 

@darkfprh , would you want to do this to dynamic Blocks as well as "ordinary" Blocks?  It makes a difference in how Blocks that need their Layer changed are found.

 

 

Kent Cooper, AIA
0 Likes
Message 4 of 6

darkfprh
Advocate
Advocate

That's it! it is absolutely I want.

 

And don't need to change dynamic blocks.

 

thank you.

Message 5 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@darkfprh wrote:

That's it! it is absolutely I want.

And don't need to change dynamic blocks.

....


This seems to do that, in very limited testing:

 

(defun C:M2LB0 ; = More-than-2-Layer Blocks to layer 0
  (/ blk ent blkname layers ss)
  (while (setq blk (tblnext "block" (not blk))); step through Block table
    (setq
      ent (tblobjname "block" (setq blkname (cdr (assoc 2 blk))))
      layers nil ; clear from previous Block if applicable
    ); setq
    (while
      (and
        (< (length layers) 3); hasn't yet exceeded 2 [or doesn't exist yet]
        (setq ent (entnext ent)); step through Block ingredients
      ); and
      (if (not (member (setq lay (cdr (assoc 8 (entget ent)))) layers)); Layer name not in list yet
        (setq layers (cons lay layers)); add it
      ); if
    ); while -- stepping through Block ingredients
    (if (> (length layers) 2); Block has ingredients on more than 2 layers
      (if (setq ss (ssget "_X" (list (cons 2 blkname)))); find all insertions [if any]
        (repeat (setq n (sslength ss)); then
          (vla-put-Layer (vlax-ename->vla-object (ssname ss (setq n (1- n)))) "0")
        ); repeat
      ); if [insertions exist]
    ); if [too many Layers in Block definition]
  ); while -- stepping through Block table
  (princ)
); defun
(vl-load-com)
(prompt "\nType M2LB0 to change More-than-2-Layer Blocks to layer 0.")

 

It doesn't account for the possibility that some such Blocks may be inserted on locked Layers.  Should it?

Kent Cooper, AIA
0 Likes
Message 6 of 6

darkfprh
Advocate
Advocate

Thank you so much! It works well. really thank you!!!

 

but I want to change block's layer "in block". (1 level inside)

so I will study and modify this lisp.

If you don't mind can you help me more?

0 Likes