Autocad Changing Hatch color

Autocad Changing Hatch color

F.Camargo
Advisor Advisor
2,825 Views
14 Replies
Message 1 of 15

Autocad Changing Hatch color

F.Camargo
Advisor
Advisor

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

0 Likes
Accepted solutions (1)
2,826 Views
14 Replies
Replies (14)
Message 2 of 15

dlanorh
Advisor
Advisor

Any chance of a dwg version saved as AutoCAD 2010 or earlier?

I am not one of the robots you're looking for

Message 3 of 15

F.Camargo
Advisor
Advisor

@dlanorh wrote:

Any chance of a dwg version saved as AutoCAD 2010 or earlier?


Hi @dlanorh 

 

Sure my friend!

 

Thanks

 

 

 

0 Likes
Message 4 of 15

dlanorh
Advisor
Advisor

These are solids, not hatches and you have some color 10, which looks like red. Are these to be changed?

I am not one of the robots you're looking for

Message 5 of 15

F.Camargo
Advisor
Advisor

@dlanorh wrote:

These are solids, not hatches and you have some color 10, which looks like red. Are these to be changed?


Yes @dlanorh .

I'd like to change all color red or 10 to 31.

 

Thanks

0 Likes
Message 6 of 15

dlanorh
Advisor
Advisor
Accepted solution

Try this. I've split the selection sets up because of the number of items, but it should take less than a minute (it did whilst testing)

 

(defun c:chc ( / *error* ss cnt ent elst)

  (defun *error* ( msg )
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun

  (setq ss (ssget "_X" '((0 . "SOLID") (-4 . "<OR") (62 . 1) (62 . 10) (-4 . "OR>"))))
  
  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq ent (ssname ss (setq cnt (1- cnt)))
                  elst (entget ent)
            )
            (entmod (subst (cons 62 31) (assoc 62 elst) elst))
          )
        )
  )
  
  (setq ss (ssget "_X" '((0 . "SOLID") (62 . 3))))
  
  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq ent (ssname ss (setq cnt (1- cnt)))
                  elst (entget ent)
            )
            (entmod (subst (cons 62 141) (assoc 62 elst) elst))
          )
        )
  )

  (princ)
)

 

 

I am not one of the robots you're looking for

Message 7 of 15

F.Camargo
Advisor
Advisor

@dlanorh 

Thank you very much!

 

Worked like a charm!!!

 

It just saved me some hours!! Thank you

 

Fabricio

0 Likes
Message 8 of 15

ronjonp
Mentor
Mentor

@dlanorh  Did not test but I doubt breaking the two selsets would be a whole lot faster than this. You still have to iterate all the items.

 

 

(defun c:chc (/ c cnt elst ent l ss)
  (setq l '((1 31) (3 141) (10 31)))
  (if (setq ss (ssget "_X" '((0 . "SOLID") (-4 . "<OR") (62 . 1) (62 . 3) (62 . 10) (-4 . "OR>"))))
    (repeat (setq cnt (sslength ss))
      (setq ent	 (ssname ss (setq cnt (1- cnt)))
	    elst (entget ent)
	    c	 (assoc 62 elst)
      )
      (entmod (subst (cons 62 (cadr (assoc (cdr c) l))) c elst))
    )
  )
  (princ)
)

 

 

 

I don't usually use command calls but this is waaaay faster 🙂

 

 

(defun c:chc_cmd (/ ss)
  (if (setq ss (ssget "_X" '((0 . "SOLID") (-4 . "<OR") (62 . 1) (62 . 10) (-4 . "OR>"))))
    (command "_.chprop" ss "" "_C" 31 "")
  )
  (if (setq ss (ssget "_X" '((0 . "SOLID") (62 . 3))))
    (command "_.chprop" ss "" "_C" 141 "")
  )
  (princ)
)

;;;Command: CHC
;;;< Elapsed time: 21.531 seconds. >
;;;
;;;Command: CHC_CMD
;;;< Elapsed time: 3.11 seconds. >

 

 

Message 9 of 15

dlanorh
Advisor
Advisor

Wow! That is much faster! I didn't even consider a command call.

 

I split them because on the first attempt with a single selection set, my machine threw a momory error and crashed AutoCAD. I put down to the size of the selection set, but could also have been caused by having 4 drawings open. I didn't consider this at that time.

 

I am not one of the robots you're looking for

0 Likes
Message 10 of 15

Sea-Haven
Mentor
Mentor

Maybe scope to add more colors.

 

(defun c:chc_cmd2 (/ ss lst)
(setq lst '((1 31) (3 141) (10 31)))
(repeat (setq x (length lst))
  (if (setq ss (ssget "_X" (list (cons 0 "SOLID") (cons 62 (car (nth (setq x (- x 1)) lst))))))
    (command "_.chprop" ss "" "_C" (cadr (nth x lst)) "")
  )
)
  (princ)
)
Message 11 of 15

F.Camargo
Advisor
Advisor

Hi @ronjonp 

 

Thank you for the helptr my old friend.

 

I really apreciate that.

 

Regards

Fabrício

0 Likes
Message 12 of 15

F.Camargo
Advisor
Advisor

@Sea-Haven 

 

It is very interesting!

 

I've already tested other colors and worked fine!!

 

Thank you very much.

 

Fabrício

0 Likes
Message 13 of 15

ronjonp
Mentor
Mentor

@Sea-Haven wrote:

Maybe scope to add more colors.

 

 

(defun c:chc_cmd2 (/ ss lst)
(setq lst '((1 31) (3 141) (10 31)))
(repeat (setq x (length lst))
  (if (setq ss (ssget "_X" (list (cons 0 "SOLID") (cons 62 (car (nth (setq x (- x 1)) lst))))))
    (command "_.chprop" ss "" "_C" (cadr (nth x lst)) "")
  )
)
  (princ)
)

 


Nice idea .. I'd use foreach to simplify a bit like so:

 

(defun c:chc_cmd2 (/ ss)
  (foreach x '((1 31) (3 141) (10 31))
    (if	(setq ss (ssget "_X" (list '(0 . "SOLID") (cons 62 (car x)))))
      (command "_.chprop" ss "" "_C" (cadr x) "")
    )
  )
  (princ)
)

 

0 Likes
Message 14 of 15

ronjonp
Mentor
Mentor

@F.Camargo wrote:

Hi @ronjonp 

 

Thank you for the helptr my old friend.

 

I really apreciate that.

 

Regards

Fabrício


Glad to help 🙂

0 Likes
Message 15 of 15

sameerulcdc
Contributor
Contributor

hi
i need ur help regarding this lsp
i have solid hatch inside the block and outside also without block with different color in the dwg i need lsp to change the all color in side the block and outside also to color 254
and  if there  is option to select area by user it will be very good 

 

thank you 

0 Likes