Block lisp to change block color

Block lisp to change block color

Anonymous
Not applicable
2,131 Views
2 Replies
Message 1 of 3

Block lisp to change block color

Anonymous
Not applicable

Hi all,

 

I need a couple of lisp routines with the help of your wide knowledge:

 

1- Imagine a nested block, let's say "b1" inside "B2", both with independent objects (lines in "b1" and lines plus "b1" in

"B2") in different layers: "layer1", "layer2", "layer3" and "layer4". I would like to change all objects inside b1 and B2 ignoring objects in "layer3" and "layer4" to color "by block". Difficult?

 

2- Once I have that blocks with this "by block" condition, I need a second LISP that changes all "by block" colored elements inside b1 and B2 to "by layer" color (only color, not line type or line with).

 

Might sound silly, but it's for an specific and repetitive purpose.

 

Many thanks in advance

0 Likes
2,132 Views
2 Replies
Replies (2)
Message 2 of 3

ronjonp
Mentor
Mentor

Not exactly sure about # 2 but this should get you started.

(defun c:foo nil
  (vlax-for a (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (cond ((= 0 (vlax-get a 'islayout))
	   (vlax-for b a
	     ;; If the object can be modified 
	     (if (vlax-write-enabled-p b)
	       ;; AND it's not on a certain layer
	       (if (not (wcmatch (strcase (vla-get-layer b)) "LAYER3,LAYER4"))
		 ;; Change the color to 'ByBlock'
		 (vla-put-color b 0)
		 ;; Put these items as Bylayer?
		 (vla-put-color b 256)
	       )
	     )
	   )
	  )
    )
  )
  (princ)
)
(vl-load-com)
Message 3 of 3

Anonymous
Not applicable

Thanks rperez,

 

Your LISP works, but it converts all objects in the drawing to color "byblock".

 

I meant to change blocks individually by selecting them and applying the LISP.

 

Good work though!

0 Likes