Jump to content

AutoCad Hatch Background Color change to None


JWisniowski

Recommended Posts

I am looking to:

1. Select all hatches

2. Change all hatch background color to None.

 

That is it. i have tried so may different ways and cannot get it to work. Any assistance would be greatly appreicated.

 

(defun c:ChangeHatchColor ()
  (vl-load-com)
  (setq ss (ssget "X" '((0 . "HATCH"))))
  (if ss
    (progn
      (setq len (sslength ss))
      (repeat len
        (setq ent (ssname ss (setq len (1- len))))
        (vl-cmdf "_chprop" ent "" "b" "none")
      )
      (princ "\nBackground color set to none for all hatches.")
    )
    (princ "\nNo hatches found.")
  )
  (princ)
)

 

Link to comment
Share on other sites

What does your cad do when you type into the command line "chprop" <select entities> "b"

 

Noting here that solid hatches don't have a background colour, you might want to exclude them from the selection set (dxf code 2, 'Solid') and you can also chprop an entire selection set, you don't need to loop through each entity in turn to do so.

 

However the fix is to look at the chprop line, run it via the command line and see what happens

Edited by Steven P
Link to comment
Share on other sites

Steven,

 

Thanks for the reply. The problem with CHPROP is that you cannot "dig into" the Pattern Properties. The CHPROP only gives you "General" options to change. I am just realizing that most of my lisp deals with these options. This is turning into a bit of a bust.

Link to comment
Share on other sites

39 minutes ago, Steven P said:

What does your cad do when you type into the command line "chprop" <select entities> "b"

 

Noting here that solid hatches don't have a background colour, you might want to exclude them from the selection set (dxf code 2, 'Solid') and you can also chprop an entire selection set, you don't need to loop through each entity in turn to do so.

 

However the fix is to look at the chprop line, run it via the command line and see what happens

I am getting somewhere.... No it wont let me just run the "-HATCHEDIT"..... It keeps my selection up.

 

  (setq all-hatches (ssget "_X" '((0 . "HATCH"))))
  (if all-hatches
    (progn
      (command "_SELECT" all-hatches) ; Select all hatches
      (command "-HATCHEDIT" "CO" "." ".") ; Change hatch fill to none
      (princ (strcat "\n" (itoa (sslength all-hatches)) " hatches modified."))
    )
    (princ "\nNo hatches found.")
  )
  (princ)
)

 

Link to comment
Share on other sites

I have this somewhere but can't remember where (140 LISP files and 3 times that many snippets, got to give the brain time to think.

 

I think you'll have to look at vla-put-property-backgroundcolor or something like that. A quick check gives me the error " ; error: lisp value has no coercion to VARIANT with this type " - I'll have to remember what I saw before

Link to comment
Share on other sites

  (setq all-hatches (ssget "_X" '((0 . "HATCH"))))
  (if all-hatches
    (progn
      (setq total-hatches (sslength all-hatches))
      (setq counter 0)
      (while (< counter total-hatches)
        (setq hatch (ssname all-hatches counter))
        
        ; Change the hatch fill to none for each hatch individually
        (command "-HATCHEDIT" hatch "CO" "." ".")
        
        (setq counter (1+ counter))
      )
      (princ (strcat "\n" (itoa total-hatches) " hatches modified."))
    )
    (princ "\nNo hatches found.")
  )
  (princ)
)

 

  • Like 1
Link to comment
Share on other sites

You could add this in too:

 

(ssget "_X" '((0 . "HATCH") (-4 . "<NOT") (2 . "SOLID") (-4 . "NOT>")))

 

Solid hatches tend to be a special case, don't have all the properties of the other hatches (like background colours)

Edited by Steven P
Link to comment
Share on other sites

On 12/11/2023 at 8:30 AM, Steven P said:

You could add this in too:

 

(ssget "_X" '((0 . "HATCH") (-4 . "<NOT") (2 . "SOLID") (-4 . "NOT>")))

 

Solid hatches tend to be a special case, don't have all the properties of the other hatches (like background colours)

Or this:

(ssget "_X" '((0 . "HATCH") (2 . "~SOLID")))

 

  • Like 1
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...