Block Solid Hatch Color to Byblock

Block Solid Hatch Color to Byblock

jyan2000
Advocate Advocate
528 Views
6 Replies
Message 1 of 7

Block Solid Hatch Color to Byblock

jyan2000
Advocate
Advocate

Hello Forum , 

 

I found this lisp changes colors all SOLID pattern hatches inside blocks to white , 

how can i change color to byblock or bylayer or selected color ( red, magenta etc. ) 

 

(defun c:sol2white (/ doc)
(or *colorobject*
(setq *colorobject*
(vla-getinterfaceobject
(vlax-get-acad-object)
(strcat "AutoCAD.AcCmColor." (substr (getvar "acadver") 1 2))
)
)
)
(if
(null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255))))
(progn (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
(if (= :vlax-false (vla-get-isxref blk))
(vlax-for obj blk
(if (and (= "AcDbHatch" (vla-get-objectname obj))
(= "SOLID" (strcase (vla-get-patternname obj)))
(vlax-write-enabled-p obj)
)
(vl-catch-all-apply 'vla-put-truecolor (list obj *colorobject*))
)
)
)
)
(vla-regen doc acallviewports)
)
)
(princ)
)
(vl-load-com)
(princ)

 

 

 

Best regards 

Victor

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

komondormrex
Mentor
Mentor

hi there,

check this

(defun b_hatch_color (color)	;	0 - byblock, 1-255 - index colors, 256 - bylayer
	(vlax-map-collection (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
						'(lambda (block) (if (and (zerop (vlax-get block 'islayout))
												  (zerop (vlax-get block 'isxref))
											 )
												(vlax-map-collection block 
													'(lambda (object) (if (and (= "AcDbHatch" (vla-get-objectname object))
																			   (= "SOLID" (vla-get-patternname object))
																		  )
																		  (vl-catch-all-apply 'vla-put-color (list object color))
																	  )
													 )
											 	)
										 )
						 )
	)
	(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport)
	(princ)
)

 

0 Likes
Message 3 of 7

jyan2000
Advocate
Advocate

Thank you very much for quick respond.. I could not able to run this lips .. Which part am I doing wrong ? 

 

 

Regars, 

Victor

0 Likes
Message 4 of 7

komondormrex
Mentor
Mentor

do as follows

1. load the code in autocad.

2. call the function loaded in command line with color needed, eg. (b_hatch_color 1) - to set solid hatch color in blocks to red.

0 Likes
Message 5 of 7

paullimapa
Mentor
Mentor
Accepted solution

give this modified version called ChHatSolCol a try:

; ChHatSolCol changes Solid Hatch colors based on ACI selection
; Modified from c:sol2white
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/block-solid-hatch-color-to-byblock/m-p/12732266#M465013
(defun c:ChHatSolCol (/ doc)
(vl-load-com)
(or *colorobject*
(setq *colorobject*
(vla-getinterfaceobject
(vlax-get-acad-object)
(strcat "AutoCAD.AcCmColor." (substr (getvar "acadver") 1 2))
)
)
)
; add 255 AutoCAD Index color selection
(setq *color* (acad_colordlg 7))
;
(if
(null (vl-catch-all-error-p (vl-catch-all-apply 'vla-setrgb (list *colorobject* 255 255 255))))
(progn (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
(if (= :vlax-false (vla-get-isxref blk))
(vlax-for obj blk
(if (and (= "AcDbHatch" (vla-get-objectname obj))
(= "SOLID" (strcase (vla-get-patternname obj)))
(vlax-write-enabled-p obj)
)
;(vl-catch-all-apply 'vla-put-truecolor (list obj *colorobject*))
; change color based on selection
(vl-catch-all-apply 'vla-put-color (list obj *color*))  
;
)
)
)
)
(vla-regen doc acallviewports)
)
)
(princ)
)
(princ)

 


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

jyan2000
Advocate
Advocate

Thank you Very much.. Its works Perfect.. 

 

Best Regards 

Victor

0 Likes
Message 7 of 7

paullimapa
Mentor
Mentor

Glad to have helped… cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes