TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Fabricio28 on March 24, 2020, 08:40:27 AM

Title: changing Hatch color
Post by: Fabricio28 on March 24, 2020, 08:40:27 AM
Hi friends,

How are you?

In my project have about 300,000 pieces of hatches, there are 2 colors; red and green...
I'd like to change all red hatches to color 31 and green to 141 color.

I'm trying to using quick select, and isn't working. Maybe a lisp could help me.

Anybody could help me out, please?

File attached

Thank in advance
Fabrício
Title: Re: changing Hatch color
Post by: rayakmal on March 24, 2020, 10:01:36 AM
Hi friends,

How are you?

In my project have about 300,000 pieces of hatches, there are 2 colors; red and green...
I'd like to change all red hatches to color 31 and green to 141 color.

I'm trying to using quick select, and isn't working. Maybe a lisp could help me.

Anybody could help me out, please?

File attached

Thank in advance
Fabrício

Have you ever tried 'Filter' command ? it's one of Autocad Command.
Title: Re: changing Hatch color
Post by: alumina on March 24, 2020, 01:17:24 PM
Code: [Select]
(defun c:ch (/ dc ss k n) (vl-load-com)
  (if (setq dc (vla-get-ActiveDocument
        (vlax-get-acad-object))
          ss (ssget "X" '((0 . "hatch") (-4 . "<or")
            (62 . 1) (62 . 3) (-4 . "or>"))))
    (progn (vla-StartUndomark dc)
      (repeat (setq k (sslength ss))
        (setq k (1- k) n (vlax-ename->vla-object
          (ssname ss k)))
        (vla-put-Color n (if (= (vla-get-Color n) 1) 31 141)))
      (vla-EndUndomark dc)
    )
  ) (prin1)
)
Title: Re: changing Hatch color
Post by: ronjonp on March 24, 2020, 04:41:45 PM
Answered a few times here too: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-changing-hatch-color/m-p/9396759#M397570
Title: Re: changing Hatch color
Post by: Fabricio28 on March 25, 2020, 08:00:39 AM
Answered a few times here too: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/autocad-changing-hatch-color/m-p/9396759#M397570

You're right Ron!

By the way you helped me a lot.

Thank you
Fabício
Title: Re: changing Hatch color
Post by: Fabricio28 on March 25, 2020, 08:01:49 AM
Code: [Select]
(defun c:ch (/ dc ss k n) (vl-load-com)
  (if (setq dc (vla-get-ActiveDocument
        (vlax-get-acad-object))
          ss (ssget "X" '((0 . "hatch") (-4 . "<or")
            (62 . 1) (62 . 3) (-4 . "or>"))))
    (progn (vla-StartUndomark dc)
      (repeat (setq k (sslength ss))
        (setq k (1- k) n (vlax-ename->vla-object
          (ssname ss k)))
        (vla-put-Color n (if (= (vla-get-Color n) 1) 31 141)))
      (vla-EndUndomark dc)
    )
  ) (prin1)
)

Thank you for the help.

Fabricio