Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HATCH COLOUR LISP ROUTINE

36 REPLIES 36
Reply
Message 1 of 37
eforb
4222 Views, 36 Replies

HATCH COLOUR LISP ROUTINE

HI,

I am in need of a lisp routine which will automatically pick up all hatch and solid hatch patterns within a drawing and change the colour to colour 254.

Any help would be much appreciated.

Thank you
36 REPLIES 36
Message 21 of 37
3dwannab
in reply to: chatsupakasem

Hi, I'm trying to modify this to suit. Changing color to 255,255,255. But no luck. What I have:

;;; Change all HATCH objects color to 255,255,255
;;; DXF 62 Color number (fixed)

(defun c:hc (/ oldcmd)
(setq oldcmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "_.chprop"
(ssget "x" (list (cons 0 "HATCH")))
""
"T"
"255","255","255"
""
)
(princ "\nChange all hatch objects color to 255,255,255.")
(setvar "cmdecho" oldcmd)
(princ)
)

 Also, is it possible to change any hatch pattern to solid? Thanks.

Message 22 of 37
Kent1Cooper
in reply to: 3dwannab


@3dwannab wrote:

Hi, I'm trying to modify this to suit. Changing color to 255,255,255. But no luck. What I have:

....
(command "_.chprop" (ssget "x" (list (cons 0 "HATCH"))) "" "T" "255","255","255" ....

 Also, is it possible to change any hatch pattern to solid? Thanks.


For the color, change this line:
"255","255","255"

to

"255,255,255"

and call for the Color option before the Truecolor option, since the T option where you have it calls up the Thickness option.

 

See Message 5 on this thread for a way to change the pattern.

Kent Cooper, AIA
Message 23 of 37
3dwannab
in reply to: Kent1Cooper

I see that I should have maintained the "color" then say "truecolor" but still no luck.

 

""
"Color"
"Truecolor"
"255,255,255"
""

As for post five, I should have mentioned that I want to affect blocks that I select changing any pattern to solid and color as truecolor 255,255,255.

Message 24 of 37
Kent1Cooper
in reply to: 3dwannab

It works for me for "top-level" Hatch entities.  For those inside Blocks, a Search for something like inside Blocks will lead you to a lot of things that dig into Block definitions and work with the entities in there.  Perhaps this one will already do just what you want, but I haven't tried it.

Kent Cooper, AIA
Message 25 of 37
3dwannab
in reply to: Kent1Cooper

I already have that, it's great but need to do a specific task, That script does not change hatch patterns nor does it change any color to the color 255,255,255. I'll try your suggestion when I finish work. And try get my head around it. I gave it a go but no joy.
Message 26 of 37
hmsilva
in reply to: 3dwannab

A quick and dirty one, using command calls and don't test if the object layers are locked...

 

(defun c:hc ( / I OLDCMD SS)
  (if (setq ss (ssget "x" (list (cons 0 "HATCH") (cons 410 (getvar 'CTAB)))))
    (progn
      (setq oldcmd (getvar "cmdecho"))
      (setvar "cmdecho" 0)
      	(setq i 0)
      (repeat (sslength ss)
	(command "-HATCHEDIT" (ssname ss i) "P" "S" "")
	(setq i (1+ i))
      )
      (command "_.chprop" ss "" "_C" "T" "255,255,255" "")
      (princ "\nChange all hatch objects to Solid and color to 255,255,255.")
      (setvar "cmdecho" oldcmd)
    )
  )
  (princ)
)

 

HTH

Henrique

EESignature

Message 27 of 37
3dwannab
in reply to: hmsilva

Thanks, but it only works inside the current drawing and not block entities.

Message 28 of 37
hmsilva
in reply to: 3dwannab


@3dwannab wrote:

Thanks, but it only works inside the current drawing and not block entities.


You're welcome!

 

I know, I just correct your code and add the "change hatch pattern" as you had requested at your post #21 ...

 

Currently I don't have any free time, but if anyone else step in, later on i'll post a new code to process all layouts and blocks.

 

Henrique

EESignature

Message 29 of 37
Kent1Cooper
in reply to: 3dwannab


@3dwannab wrote:
.... I should have mentioned that I want to affect blocks that I select changing any pattern to solid and color as truecolor 255,255,255....
and later:
Thanks, but it only works inside the current drawing and not block entities.


I take it from the first line above that you don't want them changed in all Block definitions as hmsilva is offering to work out.  The term "current drawing" in the second suggests to me that you may also be talking about changing them in Xrefs -- is that correct?

Kent Cooper, AIA
Message 30 of 37
3dwannab
in reply to: hmsilva

Thanks for your time, to recap. (seems to be slight confusion). What I require.

 

Run lisp:

Select block and/or mulitple blocks (Not xrefs)

change any hatch to solid

change hatch to 255,255,255

 

If it works with dynamic blocks that would be great.

Message 31 of 37
Kent1Cooper
in reply to: 3dwannab

Well, I thought I had it about licked, but this doesn't quite work:

 

(defun C:HBSC ; = Hatch in Blocks to Solid and Color
  (/ ss blkObj blkName blkNameList ent edata)
  (prompt "\nTo Change all Hatch patterns in selected Blocks to Solid pattern and Color 255,255,255,")
  (if (setq ss (ssget '((0 . "INSERT")))); picked at least one Insert object
    (progn ; then
      (repeat (sslength ss)
        (setq
          blkObj (vlax-ename->vla-object (ssname ss 0))
          blkName
            (vlax-get-property
              blkObj
              (if (vlax-property-available-p blkObj 'EffectiveName)
                'EffectiveName
                'Name
              ); if
            ); ...property & blkName
        ); setq
        (if
          (and
            (member '(1 . "") (entget (tblobjname "block" blkName))); not an Xref [no Path]
            (not (member blkName blkNameList)); not already in list
          ); and
          (setq blkNameList (cons blkName blkNameList))
        ); if
        (ssdel (ssname ss 0) ss)
      ); repeat
      (foreach blkName blkNameList
        (setq ent (tblobjname "block" blkName))
        (while (setq ent (entnext ent)); step through components
          (if (= (cdr (assoc 0 (setq edata (entget ent)))) "HATCH")
            (progn
              (entmod (subst '(2 . "SOLID") (assoc 2 edata) edata))
              (command "_.chprop" ent "" "_color" "_truecolor" "255,255,255" "")
            ); progn
          ); if
        ); while
      ); foreach

      (command "_.regen"); update display of Hatches
    ); progn
  ); if
); defun

 

The red part is invalid, because you can't use CHPROP on a nested entity.  I tried to figure out how to do it with (subst)/(entmod), but something with a truecolor of 255,255,255 contains a color entry of (62 . 7), so I'm not sure how it holds that information as entity data.  It can probably be done with VLA Properties, e.g:

 

(vla-put-TrueColor (vlax-ename->vla-object ent) {SomethingOrOther})

 

but I'm not sure how to translate the TrueColor number group into the VLA Object form needed [I imagine someone out there knows how].

 

If I comment out the color-change part, the rest of it works in limited testing.

Kent Cooper, AIA
Message 32 of 37
hmsilva
in reply to: Kent1Cooper

Perhaps something like this (untested)

 

(progn
;(entmod (subst '(2 . "SOLID") (assoc 2 edata) edata))
  (setq edata (subst '(2 . "SOLID") (assoc 2 edata) edata))
  (if (assoc 420 edata)
    (setq edata	(subst '(420 . 16777215) (assoc 420 edata) edata)
	  edata	(subst '(62 . 7) (assoc 62 edata) edata)
    )
    (setq edata	(append edata (list (cons 420 16777215)))
	  edata	(subst '(62 . 7) (assoc 62 edata) edata)
    )
  )
  (entmod edata)
;(command "_.chprop" ent "" "_color" "_truecolor" "255,255,255" "")
); progn

 

 

Henrique

EESignature

Message 33 of 37
3dwannab
in reply to: hmsilva

Big thanks to kent copper and hmsilva. I combined the code to get:

(defun C:HBSC ; = Hatch in Blocks to Solid and Color
  (/ ss blkObj blkName blkNameList ent edata)
  (prompt "\nTo Change all Hatch patterns in selected Blocks to Solid pattern and Color 255,255,255,")
  (if (setq ss (ssget '((0 . "INSERT")))); picked at least one Insert object
    (progn ; then
      (repeat (sslength ss)
        (setq
          blkObj (vlax-ename->vla-object (ssname ss 0))
          blkName
            (vlax-get-property
              blkObj
              (if (vlax-property-available-p blkObj 'EffectiveName)
                'EffectiveName
                'Name
              ); if
            ); ...property & blkName
        ); setq
        (if
          (and
            (member '(1 . "") (entget (tblobjname "block" blkName))); not an Xref [no Path]
            (not (member blkName blkNameList)); not already in list
          ); and
          (setq blkNameList (cons blkName blkNameList))
        ); if
        (ssdel (ssname ss 0) ss)
      ); repeat
      (foreach blkName blkNameList
        (setq ent (tblobjname "block" blkName))
        (while (setq ent (entnext ent)); step through components
          (if (= (cdr (assoc 0 (setq edata (entget ent)))) "HATCH")
            (progn
;(entmod (subst '(2 . "SOLID") (assoc 2 edata) edata))
  (setq edata (subst '(2 . "SOLID") (assoc 2 edata) edata))
  (if (assoc 420 edata)
    (setq edata	(subst '(420 . 16777215) (assoc 420 edata) edata)
	  edata	(subst '(62 . 7) (assoc 62 edata) edata)
    )
    (setq edata	(append edata (list (cons 420 16777215)))
	  edata	(subst '(62 . 7) (assoc 62 edata) edata)
    )
  )
  (entmod edata)
;(command "_.chprop" ent "" "_color" "_truecolor" "255,255,255" "")
); progn
          ); if
        ); while
      ); foreach

      (command "_.regen"); update display of Hatches
    ); progn
  ); if
); defun

 I done a quick test on a dynamic block but it has no effect (no biggie). Still, this is very easy for making sure the color and hatch is right for making blocks which wipeout any stuff behind the object. Thanks guys.

Message 34 of 37
LISPlearner
in reply to: 3dwannab

Good afternoon! 

I realize this post is pretty old, but I am looking for something similar. 

 

basically I need it to autoselect all blocks in modelspace on layer FUTURE

Then Change the hatching pattern within those blocks from SOLID to ANSI31 and add a background color of 255,255,255, then change the scale of the hatch to 12.

 

Does anyone know how to get to that?

Message 35 of 37
Garga
in reply to: Kent1Cooper

hi, this lisp is not working on my block.
I want to change all blocks hatch black colour to white. Some drawings have >100 such blocks and they have all background colour is black, I want them white.

Message 36 of 37
Kent1Cooper
in reply to: Garga

Which message of mine is this in reply to?

The color called "white" is color 7, which is black on a white background [note the color icon split diagonally black/white].  Try color 254, which is so pale a grey that it may as well be white.  Or try omitting the Hatches from the Blocks entirely.

Kent Cooper, AIA
Message 37 of 37
Garga
in reply to: Kent1Cooper

 

I don't know, how to add colour 7 to replace with colour 254 here in your code to solve my problem.

(defun C:HBSC ; = Hatch in Blocks to Solid and Color
  (/ ss blkObj blkName blkNameList ent edata)
  (prompt "\nTo Change all Hatch patterns in selected Blocks to Solid pattern and Color 255,255,255,")
  (if (setq ss (ssget '((0 . "INSERT")))); picked at least one Insert object
    (progn ; then
      (repeat (sslength ss)
        (setq
          blkObj (vlax-ename->vla-object (ssname ss 0))
          blkName
            (vlax-get-property
              blkObj
              (if (vlax-property-available-p blkObj 'EffectiveName)
                'EffectiveName
                'Name
              ); if
            ); ...property & blkName
        ); setq
        (if
          (and
            (member '(1 . "") (entget (tblobjname "block" blkName))); not an Xref [no Path]
            (not (member blkName blkNameList)); not already in list
          ); and
          (setq blkNameList (cons blkName blkNameList))
        ); if
        (ssdel (ssname ss 0) ss)
      ); repeat
      (foreach blkName blkNameList
        (setq ent (tblobjname "block" blkName))
        (while (setq ent (entnext ent)); step through components
          (if (= (cdr (assoc 0 (setq edata (entget ent)))) "HATCH")
            (progn
;(entmod (subst '(2 . "SOLID") (assoc 2 edata) edata))
  (setq edata (subst '(2 . "SOLID") (assoc 2 edata) edata))
  (if (assoc 420 edata)
    (setq edata	(subst '(420 . 16777215) (assoc 420 edata) edata)
	  edata	(subst '(62 . 7) (assoc 62 edata) edata)
    )
    (setq edata	(append edata (list (cons 420 16777215)))
	  edata	(subst '(62 . 7) (assoc 62 edata) edata)
    )
  )
  (entmod edata)
;(command "_.chprop" ent "" "_color" "_truecolor" "255,255,255" "")
); progn
          ); if
        ); while
      ); foreach

      (command "_.regen"); update display of Hatches
    ); progn
  ); if
); defun

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost