Catch all drawing objects in layer "0" (incl. inside normall/dynamic blocks) and place them in another layer

Catch all drawing objects in layer "0" (incl. inside normall/dynamic blocks) and place them in another layer

lzedCB
Advocate Advocate
428 Views
6 Replies
Message 1 of 7

Catch all drawing objects in layer "0" (incl. inside normall/dynamic blocks) and place them in another layer

lzedCB
Advocate
Advocate

Hello, I've tried to find an automatic LISP here in forum that do this task, but I couldn't find any: 

 

I would like to run an automatic LISP (without user input) that "catches" only entities (texts, lines, circles, polylines, etc.) that are in layer "0", including those ones inside normal and dynamic blocks, and move or place them inside a layer called "00" that has a 8 color.

 

Anyone can help me with a LISP that does this task? Thanks in advance!

0 Likes
Accepted solutions (2)
429 Views
6 Replies
Replies (6)
Message 2 of 7

komondormrex
Mentor
Mentor
Accepted solution

hey,

check this one

 

(defun c:set_all_layer_0->00 (/ layer_00)
  	(if (vl-catch-all-error-p (setq layer_00 (vl-catch-all-apply 'vla-add (list (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "00"))))
	  	(vla-put-color (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "00") 8)
	  	(vla-put-color layer_00 8)
	)
	(vlax-map-collection (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
		'(lambda (block)
			(if (and
				(zerop (vlax-get block 'isxref))
				(not (= "AcDbBlockReference" (vla-get-objectname block)))
			    )
				(vlax-map-collection block
					'(lambda (object)
						(cond
							(
								(= "0" (vla-get-layer object))
									(vla-put-layer object "00")
							 		(vla-put-color object 256)
							)
							(t)
						)
					 )
				)
			)
		 )
	)
  	(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acActiveViewport)
	(princ)
)

 

0 Likes
Message 3 of 7

paullimapa
Mentor
Mentor
(defun c:ch0to00 (/ ss)
(if(setq ss (ssget "_X" '((8 . "0")))) 
(vl-cmdf "_.chprop" ss "" "_la" "00" ""))
(princ)
)

Try Ch0to00 

If you need to also make layer 00 with color 8 then include this in code 

(vl-cmdf "_.Layer" "_M" "00" "_C" 8 "" "")

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 7

lzedCB
Advocate
Advocate
This worked like a CHARM! For other people that wants to make this for other layers, just replace the "00" for your intended layer. Really appreciate your skills and help my friend!
0 Likes
Message 5 of 7

lzedCB
Advocate
Advocate

I've forgot to mention: is there any way to modify this LISP so the objects in layer "0" retains/preserve their original colors (applied by object) before being moved to the new layer "00"? Thanks!

0 Likes
Message 6 of 7

komondormrex
Mentor
Mentor
Accepted solution

like that?

(defun c:set_all_layer_0->00 (/ layer_00)
  	(if (vl-catch-all-error-p (setq layer_00 (vl-catch-all-apply 'vla-add (list (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "00"))))
	  	(vla-put-color (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "00") 8)
	  	(vla-put-color layer_00 8)
	)
	(vlax-map-collection (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
		'(lambda (block)
			(if (and
				(zerop (vlax-get block 'isxref))
				(not (= "AcDbBlockReference" (vla-get-objectname block)))
			    )
				(vlax-map-collection block
					'(lambda (object)
						(cond
							(
								(= "0" (vla-get-layer object))
									(vla-put-layer object "00")
;;;							 		(vla-put-color object 256)
							)
							(t)
						)
					 )
				)
			)
		 )
	)
  	(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acActiveViewport)
	(princ)
)
0 Likes
Message 7 of 7

lzedCB
Advocate
Advocate
Thanks Wizard! That worked perfectly! 🙂
0 Likes