Jump to content

Method to change hatch background in multi block to none...


Recommended Posts

Posted

I have a drawing that was exported from Revit that has multiple blocks with a hatch background set to a color and I need them all set to none. I can use the blockeditor and do them one at a time but there are over 1000 blocks. Looking for a way to get them all at once. Small example file attached.

 

Thank You

Brian

 

 

block-hatch-fix-.dwg

Posted (edited)

Like this?

(defun c:effh (/ a c d)
  ;; RJP » 2020-11-16
  (vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
    (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  )
  (vlax-for b (vla-get-blocks d)
    ;; This line will only process block definitions
    (if	(= 0 (vlax-get b 'isxref) (vlax-get b 'islayout))
      (vlax-for	o b
	(cond ((and (vlax-write-enabled-p o) (wcmatch (vla-get-objectname o) "AcDbHatch"))
	       (setq c (vla-get-backgroundcolor o))
	       (vla-setrgb c 0 0 0)
	       (vla-put-backgroundcolor o c)
	      )
	)
      )
    )
  )
  (foreach l a (vlax-put l 'lock -1))
  (vla-regen d acallviewports)
  (princ)
)

 

Edited by ronjonp
  • Like 2
Posted

That helps but deletes the hatch, I would like to leave the hatch just set the background color to "None".

 

Brian

Posted
18 minutes ago, wee said:

That helps but deletes the hatch, I would like to leave the hatch just set the background color to "None".

 

Brian

Code updated above.

Posted

Yes...That did the trick.

 

Thank You very much....

Brian

Posted
3 hours ago, wee said:

Yes...That did the trick.

 

Thank You very much....

Brian

Glad to help. 🍻

  • 2 years later...
Posted
(setq c (vla-get-backgroundcolor o))
	       (vla-setrgb c 0 0 0)
	       (vla-put-backgroundcolor o C)

how can i change to none

  • 2 weeks later...
Posted

how can I remove the hatch background colour means I need to set none

  • 1 month later...
Posted

please someone help with this,
Have lots of objects in the block. I need to change the Hatch background colour to none. now am doing one by one 

Posted
8 hours ago, Ajmal said:

please someone help with this,
Have lots of objects in the block. I need to change the Hatch background colour to none. now am doing one by one 

Post an example drawing of before and after of what you're looking for.

Posted
14 hours ago, ronjonp said:

Post an example drawing of before and after of what you're looking for.

while I am using this, all hatches will add background 0,0,0. if there is no background colour also will be changed to this 

image.png.f249e236fb1ff9f20cb46e0808da3939.png

 

 

 

 

I have different Hatch background colours. Someone is true colours someone is index colour and someone is without background colour (none).
Need all hatch without background colour (need to set none). but I don't want to change any hatch type, pattern, and general colour. need to change background to none

HATCH.dwg

Posted (edited)

I'm not sure I follow .. the code HERE does that already? Nevermind .. I see what you are saying... let me take a look.

 

Try this version:

(defun c:foo (/ a c d)
  ;; RJP » 2023-08-13
  ;; Sets hatch background color in blocks to 'none'
  (vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
    (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  )
  (vlax-for b (vla-get-blocks d)
    ;; This line will only process block definitions
    (if	(= 0 (vlax-get b 'isxref) (vlax-get b 'islayout))
      (vlax-for	o b
	(cond ((and (vlax-write-enabled-p o) (wcmatch (vla-get-objectname o) "AcDbHatch"))
	       (setq c (vla-get-backgroundcolor o))
	       (vla-put-EntityColor c -939524096)
	       (vla-put-backgroundcolor o c)
	      )
	)
      )
    )
  )
  (foreach l a (vlax-put l 'lock -1))
  (vla-regen d acallviewports)
  (princ)
)

 

Edited by ronjonp
  • Like 2
  • Thanks 1
Posted
On 13/08/2023 at 19:26, ronjonp said:

I'm not sure I follow .. the code HERE does that already? Nevermind .. I see what you are saying... let me take a look.

 

Try this version:

(defun c:foo (/ a c d)
  ;; RJP » 2023-08-13
  ;; Sets hatch background color in blocks to 'none'
  (vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
    (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  )
  (vlax-for b (vla-get-blocks d)
    ;; This line will only process block definitions
    (if	(= 0 (vlax-get b 'isxref) (vlax-get b 'islayout))
      (vlax-for	o b
	(cond ((and (vlax-write-enabled-p o) (wcmatch (vla-get-objectname o) "AcDbHatch"))
	       (setq c (vla-get-backgroundcolor o))
	       (vla-put-EntityColor c -939524096)
	       (vla-put-backgroundcolor o c)
	      )
	)
      )
    )
  )
  (foreach l a (vlax-put l 'lock -1))
  (vla-regen d acallviewports)
  (princ)
)

 

wow great.  thanks, ronjonp

Posted
5 hours ago, Ajmal said:

wow great.  thanks, ronjonp

:beer:

  • Thanks 1

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...