Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Block layer fix for multiple blocks

DC-MWA
Collaborator

Block layer fix for multiple blocks

DC-MWA
Collaborator
Collaborator

Hello,

I have inherited a project and received cad files for the project. I need help fixing the block layers.

All the blocks are on layer 0, and each block has a layer inside the block.

I need to put the block on the layer inside the block, and set the block layer to 0.

Example.

Existing:  Sink block on layer "0" and geometry inside block is on layer "A-Appl".

Desired: put Sink block on layer "A-Appl" and geometry inside block to be on layer "0".

 

There are dozens of blocks that need to be corrected. I'm hoping to selected multiple blocks at once.

I'm hoping somebody has run into this before and has a solution.

Thanks in advance for your assistance.

-dc

0 Likes
Reply
Accepted solutions (1)
769 Views
13 Replies
Replies (13)

komondormrex
Advisor
Advisor

hey there,

yet another one. no checks on layers' lock.

 

 

 

(defun c:change_layer_all_inserts ( / block_definition processed_list insert_layer block_name insert_dxf)
	(vlax-map-collection (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
		'(lambda (insert)
			(if (and 
				 (= "AcDbBlockReference" (vla-get-objectname insert))
				 (zerop (vlax-get (setq block_definition (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) 
										   (vla-get-effectivename insert)
						 			)
						  ) 'isxref
					)
				 )
		      		(if (not (assoc (setq block_name (vla-get-name block_definition)) processed_list))
				  	(setq processed_list (append processed_list (list (cons (vla-get-name block_definition) (vla-get-layer (vla-item block_definition 0))))))
				  	(vla-put-layer insert (cdr (assoc block_name processed_list)))  
				) 
			)
				(progn
					(vlax-map-collection block_definition
						'(lambda (object)
							(progn
								(vla-put-layer object "0")
	;								(vla-put-color object 256)
							)
						 )
					)
				  	(vla-put-layer insert (cdr (assoc block_name processed_list)))  
				)
		    	)
		 )
	)
  	(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport) 
  	(princ)
)

 

 

updated_2

smallฦ‘ish
Advocate
Advocate

Try this, got from internet only.

0 Likes

DC-MWA
Collaborator
Collaborator

I appreciate the replies. All of these only set the block layers to "0" which is half the battle.

I need to extract the layer inside the block put the block on that layer in addition to setting the layer inside the block to "0".

0 Likes

pendean
Community Legend
Community Legend

@DC-MWA wrote:

I appreciate the replies. All of these only set the block layers to "0" which is half the battle.

I need to extract the layer inside the block put the block on that layer in addition to setting the layer inside the block to "0".


If you want to do the work... here is a lisp that is your requested process https://forums.augi.com/showthread.php?18929-Block-layer-Lisp-Finder&p=119922&viewfull=1#post119922 and you have the latter requested process above.

 

HTH

0 Likes

DC-MWA
Collaborator
Collaborator

Thank you. This does get the layer from the blocks selected. This is beyond my limited skill set. 

Worse case I will get to work manually putting blocks on the appropriate layers.

 

0 Likes

komondormrex
Advisor
Advisor

sure, check update

ronjonp
Advisor
Advisor

@DC-MWA Give this a shot:

 

(defun c:foo (/ blk lyr nm r)
  ;; RJP ยป 2024-01-30
  (vlax-for a (setq blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
    (if	(and (= 0 (vlax-get a 'islayout) (vlax-get a 'isxref)) (setq nm (vla-get-name a)))
      (vlax-for	b a
	(and nm (/= "0" (vla-get-layer b)) (setq r (cons (list nm (vla-get-layer b)) r)))
	(vl-catch-all-apply 'vla-put-layer (list b "0"))
	(setq nm nil)
      )
    )
  )
  (vlax-for a blk
    (if	(= -1 (vlax-get a 'islayout))
      (vlax-for	b a
	(and (= "AcDbBlockReference" (vla-get-objectname b))
	     (setq lyr (cadr (assoc (vla-get-effectivename b) r)))
	     (vl-catch-all-apply 'vla-put-layer (list b lyr))
	)
      )
    )
  )
  (princ)
)

 

0 Likes

DC-MWA
Collaborator
Collaborator

This works. Is it possible to make it work on selected blocks only. Because if it does all the blocks, the blocks that are setup correctly end up on layer 0.

0 Likes

ronjonp
Advisor
Advisor
Accepted solution

@DC-MWA Try the code again .. I put an exception if the internal layer is already "0".

 

(and nm (/= "0" (vla-get-layer b)) (setq r (cons (list nm (vla-get-layer b)) r)))

 

0 Likes

DC-MWA
Collaborator
Collaborator

Thank you very very much.

I am burning through drawings lighting fast!!!

0 Likes

ronjonp
Advisor
Advisor

@DC-MWA wrote:

Thank you very very much.

I am burning through drawings lighting fast!!!


You're welcome! ๐Ÿ˜

0 Likes

studiocz
Observer
Observer

can you please explain me how to use the written lisps/  i know how to load lisp files but dont know how to turn the written comand to a file and load 

 

0 Likes

Sea-Haven
Mentor
Mentor

The program is ran by typing Foo on command line after loading. I would rename it to something else that matches the task. Blayfix ??

 

(defun c:foo (/ blk lyr nm r)

 

 The C: implies that what follows can be used as a command.

 

The second option is to add (c:foo) as the last line in the lisp this will run it after its loaded, if you want to run again just type FOO. 

 

(princ)
)
(C:foo)

 

0 Likes