Change the Hacth color to true color

Change the Hacth color to true color

F.Camargo
Advisor Advisor
1,934 Views
13 Replies
Message 1 of 14

Change the Hacth color to true color

F.Camargo
Advisor
Advisor

Hi guys

 

I'm looking for a code to change all hacth solid color 8 in layout model to a true color 248,215,49.

 

Is it possible, friends?

 

I have several dwg files, and each file has about 20 layout model. Smiley Embarassed

 

Thanks

Fabrício

0 Likes
Accepted solutions (2)
1,935 Views
13 Replies
Replies (13)
Message 2 of 14

CADaSchtroumpf
Advisor
Advisor

Hi,

 

I use this (is not mine), can help you?

 

;;http://www.autolisp.mapcar.net/acifarben.html
(defun ACI2RGB (n / l1 l3)
  (cond
    ( (or(> n 255)(< n 1))nil)
    ( (> 7 n 0)(aci2rgb(+ 10(* 40(1- n)))))
    ( (> 250 n 9)
      (setq l1
       '(0 1 2 3 4 4 4 4 4 4 4 4 4 3 2 1 0 0 0 0 0 0 0 0)
      )
      (setq l3 '(1 0.8 0.6 0.5 0.3))
      (mapcar
       '(lambda(v w / )
          (fix
            (* 255
              (+
                (*
                  0.25
                  (nth(rem(+(1-(/ n 10))v)24)l1)
                  (nth(/(rem n 10)2)l3)
                )
                (*
                  (rem n 2)
                  0.125
                  (nth(rem(+(1-(/ n 10))w)24)l1)
                  (nth(/(rem n 10)2)l3)
                )
              )
            )
          )
        )
       '(8 0 16)
       '(20 12 4)
      )
    )
    (1
      (apply
       '(lambda(v w / )(list w w w))
        (assoc n
          '((7 255)(8 128)(9 192)(250 51)(251 91)(252 132)
                             (253 173)(254 214)(255 255)))
      )
    )
  )
)
(defun RGB2TrueColor (l_RGB / )
	(+ (lsh (car l_RGB) 16) (lsh (cadr l_RGB) 8) (caddr l_RGB))
)
(defun c:256toRGB ( / );js n dxf_ent T_C)
	(while (null (setq js (ssget "_X" '((-4 . "<") (62 . 256))))))
	(setq n -1)
	(repeat (sslength js)
		(setq T_C (RGB2TrueColor (ACI2RGB (cdr (assoc 62 (setq dxf_ent (entget (ssname js (setq n (1+ n))))))))))
		(entmod
			(append
				dxf_ent
				(list (cons 420 T_C))
			)
		)
	)
	(prin1)
)
Message 3 of 14

F.Camargo
Advisor
Advisor

@CADaSchtroumpf

Thank you for the quick replay.

 

The code isn't working properly friend.

 

I'm attaching a file to explain better my task.

 

Regards

 

 

0 Likes
Message 4 of 14

CADaSchtroumpf
Advisor
Advisor
Accepted solution

For you, can be only:

 

(defun RGB2TrueColor (l_RGB / )
  (+ (lsh (car l_RGB) 16) (lsh (cadr l_RGB) 8) (caddr l_RGB))
)
(defun c:256toRGB ( / js n dxf_ent T_C)
  (setq js (ssget "_X" '((0 . "HATCH") (67 . 1) (-4 . "=") (62 . 8))))
  (cond
    (js
      (repeat (setq n (sslength js))
        (setq
          dxf_ent (entget (ssname js (setq n (1- n))))
          T_C (RGB2TrueColor '(248 215 49))
        )
        (entmod
          (append
            dxf_ent
            (list (cons 420 T_C))
          )
        )
      )
    )
  )
  (prin1)
)
Message 5 of 14

F.Camargo
Advisor
Advisor

@CADaSchtroumpf wrote:

For you, can be only:

 

(defun RGB2TrueColor (l_RGB / )
  (+ (lsh (car l_RGB) 16) (lsh (cadr l_RGB) 8) (caddr l_RGB))
)
(defun c:256toRGB ( / js n dxf_ent T_C)
  (setq js (ssget "_X" '((0 . "HATCH") (67 . 1) (-4 . "=") (62 . 8))))
  (cond
    (js
      (repeat (setq n (sslength js))
        (setq
          dxf_ent (entget (ssname js (setq n (1- n))))
          T_C (RGB2TrueColor '(248 215 49))
        )
        (entmod
          (append
            dxf_ent
            (list (cons 420 T_C))
          )
        )
      )
    )
  )
  (prin1)
)

When I invoke the command nothing happened.

Could you help me, please?

 

Thanks

0 Likes
Message 6 of 14

DannyNL
Advisor
Advisor

Here another solution that also should work.

 

(defun c:Test (/ T_Selection T_Object T_Color)
   (if
      (setq T_Selection (ssget "_X" '((0 . "HATCH")(62 . 8)(410 . "Model"))))
      (progn
         (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (foreach T_Hatch (ssnamex T_Selection)
            (setq T_Object (vlax-ename->vla-object (cadr T_Hatch)))
            (setq T_Color (vla-get-TrueColor T_Object))
            (vla-SetRGB T_Color 248 215 49)
            (vla-put-TrueColor T_Object T_Color)
         )
         (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (princ (strcat "\n ** Modified " (itoa (sslength T_Selection)) " hatch objects."))
      )
      (princ "\n ** Nothing found.")
   )
   (princ)
)
Message 7 of 14

F.Camargo
Advisor
Advisor

@DannyNL wrote:

Here another solution that also should work.

 

(defun c:Test (/ T_Selection T_Object T_Color)
   (if
      (setq T_Selection (ssget "_X" '((0 . "HATCH")(62 . 8)(410 . "Model"))))
      (progn
         (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (foreach T_Hatch (ssnamex T_Selection)
            (setq T_Object (vlax-ename->vla-object (cadr T_Hatch)))
            (setq T_Color (vla-get-TrueColor T_Object))
            (vla-SetRGB T_Color 248 215 49)
            (vla-put-TrueColor T_Object T_Color)
         )
         (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (princ (strcat "\n ** Modified " (itoa (sslength T_Selection)) " hatch objects."))
      )
      (princ "\n ** Nothing found.")
   )
   (princ)
)

Hi

Isn't working too, my friend.

 

Command: TEST
 ** Nothing found.

 

The hatch is the layout space.

 

Thanks

 

0 Likes
Message 8 of 14

CADaSchtroumpf
Advisor
Advisor

This your drawing exemple, the code (with command 256toRGB) is work's for me! Change the color of hatch to 248,215,49 in any layouts

0 Likes
Message 9 of 14

DannyNL
Advisor
Advisor
Accepted solution

So it's in paperspace and not modelspace?

Because you mentioned the the layout model in your first post.

 

But if you want to change hatch in the current layout tab, you can use:

 

(defun c:Test (/ T_Selection T_Object T_Color)
   (if
      (setq T_Selection (ssget "_X" (list '(0 . "HATCH") '(62 . 8) (cons 410  (getvar "CTAB")))))
      (progn
         (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (foreach T_Hatch (ssnamex T_Selection)
            (setq T_Object (vlax-ename->vla-object (cadr T_Hatch)))
            (setq T_Color (vla-get-TrueColor T_Object))
            (vla-SetRGB T_Color 248 215 49)
            (vla-put-TrueColor T_Object T_Color)
         )
         (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (princ (strcat "\n ** Modified " (itoa (sslength T_Selection)) " hatch objects."))
      )
      (princ "\n ** Nothing found.")
   )
   (princ)
)

Or if you just want to change all hatches independent of layout and space use

 

...
...
(setq T_Selection (ssget "_X" '((0 . "HATCH") (62 . 8))))
...
...
Message 10 of 14

F.Camargo
Advisor
Advisor

@CADaSchtroumpf wrote:

This your drawing exemple, the code (with command 256toRGB) is work's for me! Change the color of hatch to 248,215,49 in any layouts


I'm so sorry.

You're right! Smiley Embarassed

 

Worked as a charm.Smiley Happy

 

I'm really happy.

Thank you very much.

 

Fabrício

 

0 Likes
Message 11 of 14

CADaSchtroumpf
Advisor
Advisor

If you change

 

(setq T_Selection (ssget "_X" '((0 . "HATCH")(62 . 8)(410 . "Model"))))
by
(setq T_Selection (ssget "_X" '((0 . "HATCH")(62 . 8)(67 . 1))))

it's work's also for c:Test

Message 12 of 14

F.Camargo
Advisor
Advisor

@DannyNL

Thank you for the help too.

 

Worked Fine! Smiley Happy

 

Fabrício

Message 13 of 14

DannyNL
Advisor
Advisor

Yes, you are absolutely right.

But I didn't check the test drawing and only went with the description of the first post

 

'I'm looking for a code to change all hacth solid color 8 in layout model to a true color 248,215,49.'

 

When I'd my code finished you already posted yours, so I just added mine as well (but still without checking the test drawing.......my mistake Smiley Wink )

0 Likes
Message 14 of 14

CADaSchtroumpf
Advisor
Advisor

I have make the same error layout model , but i have modified my post and Camargo have try (i Think my first code) for answer that it's not work.

0 Likes