Change hatch transparency in nested blocks

Change hatch transparency in nested blocks

Anonymous
Not applicable
3,186 Views
17 Replies
Message 1 of 18

Change hatch transparency in nested blocks

Anonymous
Not applicable

Hi guys,

 

I am new to lisp and I would like to know what line/s should I change on the lisp below to change the transparency of hatch in nested blocks. The code works perfectly in changing the hatch colour.

 

Thanks!

 

(defun c:HC ( / aDoc color)
     (vl-load-com)
     (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object))) 
     (if (setq color (acad_colordlg 7 t))
         (progn
             (vlax-for blk (vla-get-blocks aDoc)
                 (if (and
       (eq :vlax-false (vla-get-islayout blk))
       (eq :vlax-false (vla-get-isxref blk))
   )
   (vlax-for itm blk
       (if (eq  (vla-get-ObjectName itm) "AcDbHatch" )
           (vla-put-color itm color)
       )
    )
       )
          )
          (vla-regen adoc acActiveViewport)
      )
    )
    (princ)
)
0 Likes
Accepted solutions (1)
3,187 Views
17 Replies
Replies (17)
Message 2 of 18

phanaem
Collaborator
Collaborator
Accepted solution

You only need to change (setq color (acad_colordlg 7 t)) to (setq color (getstring"\nSpecify transparency (0-90): ")) and vla-put-color to vla-put-entitytransparency ,and it would work, but you also need to check the input validity, so try this:

(defun c:HT ( / aDoc tr)
     (vl-load-com)
     (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object))) 
     (if
       (progn
         (initget 132)
         (setq tr (getint "\nSpecify transparency (0-90): "))
         (cond
           ((eq (type tr) 'int)
            (if (<= 0 tr 90) (setq tr (itoa tr)))
           )
           ((eq (type tr) 'str)
            (or
              (wcmatch (strcase tr) "BYLAYER,BYBLOCK")
              (not (princ "\nInvalid value."))
            )
           )
         )
       )
       (vlax-for blk (vla-get-blocks aDoc)
         (if
           (and
             (eq :vlax-false (vla-get-islayout blk))
             (eq :vlax-false (vla-get-isxref blk))
           )
           (vlax-for itm blk
             (if
               (eq (vla-get-ObjectName itm) "AcDbHatch")
               (vla-put-entitytransparency itm tr)
             )
           )
         )
       )   
     )
     (vla-regen adoc acActiveViewport)
     (princ)
)

 

Message 3 of 18

Anonymous
Not applicable

Woah thanks! That's exactly what I am looking for!

0 Likes
Message 4 of 18

gavrielN5EPC
Observer
Observer

This does work perfectly, except I don't want the pause for user input. I always want 90 transparency. Is there anyone that can modify this so it automatically enters "90" for the transparency value, instead of pausing for user input?

0 Likes
Message 5 of 18

ronjonp
Mentor
Mentor

@gavrielN5EPC 

;; Change this
(setq tr (getint "\nSpecify transparency (0-90): "))
;; to this
(setq tr 90)
0 Likes
Message 6 of 18

gavrielN5EPC
Observer
Observer

Perfection! Thank you!!!

0 Likes
Message 7 of 18

ronjonp
Mentor
Mentor

@gavrielN5EPC You could also use this .. it won't bomb on locked layers.

 

;; Changes hatch transparency in blocks to 90%
(defun c:ht (/ a d)
  ;; RJP » 2024-06-28
  (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)
    (if	(= 0 (vlax-get b 'isxref) (vlax-get b 'islayout))
      (vlax-for	o b
	(and (vlax-write-enabled-p o)
	     (= (vla-get-objectname o) "AcDbHatch")
	     (vla-put-entitytransparency o 90)
	)
      )
    )
  )
  ;; Relock layers
  (foreach l a (vlax-put l 'lock -1))
  ;; Regen to see changes
  (vla-regen d 1)
  (princ)
)

 

0 Likes
Message 8 of 18

gavrielN5EPC
Observer
Observer

Thank you very much. I unlock all layers as my second step in my "process", and the transparency is way down on the list, so layers are already unlocked at that time. However, I do have another challenge for you, if you're up to it? I have a lisp routine (BG.lsp) that contains a bunch of commands and runs other lisp routines. Can you create a lisp routine that I can run, which will prompt me to browse to a folder containing multiple .dwg files, and then run my main "BG" lisp routine on all dwgs without me having to open each dwg? I have had that working years ago, but I lost it along the way.

0 Likes
Message 9 of 18

ronjonp
Mentor
Mentor

Have a read here. No need for me to reinvent the wheel 8-)

0 Likes
Message 10 of 18

gavrielN5EPC
Observer
Observer

Thank you, but my brain doesn't work that good 😞 I tried creating an .scr file with the following, but I get a message saying "Invalid file name"

 

_.open **.dwg* _.BG _.save _Y _.close

0 Likes
Message 11 of 18

ronjonp
Mentor
Mentor

Try this syntax: _.open *file* (c:bg) _.save _Y _.close

0 Likes
Message 12 of 18

gavrielN5EPC
Observer
Observer

Thank you, but I'm still getting the same message. It doesn't even bring up the "browse for folder" dialog box. As soon as I double click the scr file to run it, I get that "Invalid file name" message 😞

0 Likes
Message 13 of 18

gavrielN5EPC
Observer
Observer

I'm actually using *file* in my script. Maybe that needs to be changed to something specific for my task? But I just want to be prompted by a "browse for folder" dialog box and select the folder that I want to run my "BG.lsp" for all dwgs in that folder. The folder will change constantly, so that is why I need the "browse for folder" option.

0 Likes
Message 14 of 18

ronjonp
Mentor
Mentor

It sounds like you have not loaded Lee's code. After you've done that run 'wscript' and use the line above.

0 Likes
Message 15 of 18

gavrielN5EPC
Observer
Observer

I have not loaded that code. How do I do that? I went to both links, but I don't see specific instructions on how to load that code.

0 Likes
Message 16 of 18

ronjonp
Mentor
Mentor

@gavrielN5EPC wrote:

I have not loaded that code. How do I do that? I went to both links, but I don't see specific instructions on how to load that code.


Sorry. I'm not sure how to give you any more help. Lee's "How to Run an AutoLISP Program" page is very detailed.

 

Download this:

ronjonp_0-1719613115173.png

Then follow his instructions.

0 Likes
Message 17 of 18

sergi_triado5JXV7
Community Visitor
Community Visitor

Hi guys, can you help me with a Lisp to modify the "bylayer" transparency of block shading? Thanks.

0 Likes
Message 18 of 18

ronjonp
Mentor
Mentor

@sergi_triado5JXV7  Can you post a sample drawing with before and after?

0 Likes