Jump to content

Lisp for changing hatch colour


Alan0522

Recommended Posts

Hey guys,

 

I got a drawing which has about 200 blocks. I am wondering is there a lisp that can help to change color of all hatches within these blocks to color 253? 

 

Thank you guys

Link to comment
Share on other sites

Here's a very simple example:

(defun c:hcol ( / c d )
    (setq c 253)
    (vlax-for b (vla-get-blocks (setq d (vla-get-activedocument (vlax-get-acad-object))))
        (if (= :vlax-false (vla-get-isxref b) (vla-get-islayout b))
            (vlax-for o b
                (if (and (= "AcDbHatch" (vla-get-objectname o)) (vlax-write-enabled-p o))
                    (vla-put-color o c)
                )
            )
        )
    )
    (vla-regen d acallviewports)
    (princ)
)
(vl-load-com) (princ)

 

  • Thanks 1
Link to comment
Share on other sites

  • 3 years later...

Hey guys,

 

Is there also a way to change the properties of all the hatches in a layer (for ex layer "01211") to pattern : DOT, with scale :1.333, angle :100, color :120,120,120 and backroungcolor : none.

 

Thank you. 

Link to comment
Share on other sites

Try this

 

(defun c:hcol ( / colobj lay x obj ss ang)
(setq colObj (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))))
(vla-setRGB colObj 120 120 120)
(setq ang 100)
(setq ang (* pi (/ ang 180.0))) ; convert to radians
(setq lay (cdr (assoc 8 (entget (car (entsel "\nPick an object for layer "))))))
(setq ss (ssget "X" (list (cons 0  "HATCH")(cons 8 lay))))
(if (= ss nil)
(alert "No hatches detected")
(progn
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(vlax-put obj 'TrueColor colobj)
(vlax-put obj 'PatternScale 1.333)
(vlax-put obj 'PatternAngle ang)
)
)
)
(princ)
)

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...