TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: PPETROS on June 07, 2018, 11:41:25 AM

Title: Global change hatch background color to none (and nested hatch)
Post by: PPETROS on June 07, 2018, 11:41:25 AM
hello everyone
i am try to make a lisp routine to change globally  the hatch background color to none ,  (and nested hatch) , but  I do not.
can anyone help me. thanks
here's the routine.
Code: [Select]
;;;;Global change hatch background color to none (and nested hatch)
(defun C:test ( / *error*) (vl-load-com)
  ;;;(setq *error* (err))
  (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (if
      (not (eq (vla-get-isxref block) :vlax-true))
      (vlax-for obj block
        (if
          (eq (vla-get-objectname obj) "AcDbhatch")
          (progn
            (setq obj (vlax-ename->vla-object obj)
                  col (vla-get-backgroundcolor obj)
            )
            (vla-put-entitycolor col -939524096)
            (vla-put-backgroundcolor obj col)
            )
          )
        )
      )
    )
  ;;;(*error* nil)
  (princ)
  )
edit: code tags added
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: ronjonp on June 07, 2018, 03:08:54 PM
Perhaps this:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ a d)
  2.     (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  3.   )
  4.     (if (= 0 (vlax-get b 'isxref))
  5.       (vlax-for o b
  6.         (if (and (vlax-write-enabled-p o) (= (vla-get-objectname o) "AcDbHatch"))
  7.           (vlax-put o
  8.                     'visible
  9.                     (cond ((= 0 (vlax-get o 'visible)) -1)
  10.                           (0)
  11.                     )
  12.           )
  13.         )
  14.       )
  15.     )
  16.   )
  17.   (foreach l a (vlax-put l 'lock -1))
  18.   (vla-regen d acallviewports)
  19.   (princ)
  20. )
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: PPETROS on June 08, 2018, 11:19:55 AM
It is a good lisp, but it changes the visibility (on/off) of all the hatches. I only want to change the hatch background color to none . Thanks
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: ronjonp on June 08, 2018, 11:58:07 AM
It is a good lisp, but it changes the visibility (on/off) of all the hatches. I only want to change the hatch background color to none . Thanks
I'm not sure what you mean. You can't change the color to 'none'? Do you mean bylayer or byblock?
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: steve.carson on June 08, 2018, 12:20:30 PM
I think he means like in the attached image. I saw there is a property of the hatch called "BackgroundColor", but I don't know the first thing about dealing with VLA colors, or how to set it to None.
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: Lee Mac on June 08, 2018, 12:34:16 PM
Set it to 'None' manually, then check the value of the property and reverse engineer it  :lol:
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: PPETROS on June 08, 2018, 12:58:29 PM
i mean the hatch property, changing the background color to none, but also globally change hatch and nested hatch with lisp
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: ronjonp on June 08, 2018, 01:07:56 PM
Maybe post a sample drawing with before and after.
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: PPETROS on June 08, 2018, 01:17:57 PM
sample
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: ronjonp on June 08, 2018, 01:33:58 PM
Try this:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ c a d)
  2.     (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  3.   )
  4.     (if (= 0 (vlax-get b 'isxref))
  5.       (vlax-for o b
  6.         (cond
  7.           ((and (vlax-write-enabled-p o) (= (vla-get-objectname o) "AcDbHatch"))
  8.            (or c (progn (setq c (vla-get-backgroundcolor o)) (vla-put-entitycolor c -939524096)))
  9.            (vla-put-backgroundcolor o c)
  10.           )
  11.         )
  12.       )
  13.     )
  14.   )
  15.   (foreach l a (vlax-put l 'lock -1))
  16.   (vla-regen d acallviewports)
  17.   (princ)
  18. )
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: PPETROS on June 08, 2018, 01:47:28 PM
Excellent, that is what i wanted.
Thank you very mach
Title: Re: Global change hatch background color to none (and nested hatch)
Post by: ronjonp on June 08, 2018, 02:05:57 PM
Excellent, that is what i wanted.
Thank you very mach
Glad to help :)