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

Change all hatch to a particular layer

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
esoh
2448 Views, 7 Replies

Change all hatch to a particular layer

Can someone help me with a lisp that can select all hatch in a drawing with a layer called AELE, even if it is embedded in a block and change it to layer AHAT with Green colour?

 

The layer AHAT may or may not already exist in the drawing.

 

We need to run the lisp on a lot of drawings (exported from Revit) so I need to use the script to run this lisp on multiple drawings.

 

Thank you for your help.

 

Regards

Esther Soh

7 REPLIES 7
Message 2 of 8
Lee_Mac
in reply to: esoh

Try the following:

 

(defun c:fixhat ( / doc lay )
    (setq lay "AHAT"
          doc (vla-get-activedocument (vlax-get-acad-object))
    )
    (vla-add (vla-get-layers doc) lay)
    (vlax-for blk (vla-get-blocks doc)
        (if (= :vlax-false (vla-get-isxref blk))
            (vlax-for obj blk
                (if
                    (and
                        (= "AcDbHatch" (vla-get-objectname obj))
                        (= "AELE" (strcase (vla-get-layer obj)))
                        (vlax-write-enabled-p obj)
                    )
                    (progn
                        (vla-put-layer obj lay)
                        (vla-put-color obj acgreen)
                    )
                )
            )
        )
    )
    (vla-regen doc acallviewports)
    (princ)
)
(vl-load-com) (princ)
Message 3 of 8
esoh
in reply to: Lee_Mac

Thank you very much. It works like a dream.

Message 4 of 8
Lee_Mac
in reply to: esoh

Message 5 of 8
shawn.p.phillips
in reply to: Lee_Mac

Hey guys, I used your lisp routine and made a few modifications to do what I needed it to do which is convert any hatch named "FP_*" (the hatch has a different number after it depending on the drawing its in) to a layer that I created in another routine.  It works great but for some reason it won't convert one of the hatches.  I think the reason is that its not a block and I'm not sure this routine is picking it up.  Even if I single it out, add a line that specifically looks for the hatch name "FP_76" it won't grab it.  Can you help me out here?

 

(defun c:earth_hat254 ( / doc)
    (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))   
        (if (= :vlax-false (vla-get-isxref blk))
            (vlax-for obj blk
                (if (and (= "AcDbHatch" (vla-get-objectname obj))
                         (= "FP_*" (strcase (vla-get-patternname obj)))
                         (vlax-write-enabled-p obj)
                    )
                    (progn
                        (vla-put-layer obj "EARTH-HATCH_254")
                        (vla-put-color obj 256)
                    )
                )
            )
        )
    )
    (vla-regen doc acallviewports)
    (princ)
)
(vl-load-com) (princ)

Message 6 of 8
mtaras
in reply to: Lee_Mac

Dear Lee,

could your lisp be applied to selected block (multiple selected blocks) instead of all blocks in drawing?

I tried to ad another filter and failed (error: malformed list on input 🙂

(defun c:fixhat1 ( / doc lay ss1 )
    (setq lay "AHAT"
          doc (vla-get-activedocument (vlax-get-acad-object)
          ss1 (ssget "_X" '((0 . "INSERT")))
    )
    (vla-add (vla-get-layers doc) lay)
    (vlax-for blk (vla-get-blocks ss1)
        (if (= :vlax-false (vla-get-isxref blk))
            (vlax-for obj blk
                (if
                    (and
                        (= "AcDbHatch" (vla-get-objectname obj))
                        (= "AELE" (strcase (vla-get-layer obj)))
                        (vlax-write-enabled-p obj)
                    )
                    (progn
                        (vla-put-layer obj lay)
                    )
                )
            )
        )
    )
    (vla-regen doc acallviewports)
    (princ)
)
(vl-load-com) (princ)

Kindest regards,

 

Message 7 of 8
Kent1Cooper
in reply to: mtaras


@mtaras wrote:
.... selected block (multiple selected blocks) instead of all blocks in drawing? .... (error: malformed list on input ....
(defun c:fixhat1 ( / doc lay ss1 )
    (setq lay "AHAT"
          doc (vla-get-activedocument (vlax-get-acad-object)) ; <-- add right parenthesis
ss1 (ssget "_X" '((0 . "INSERT"))); <-- remove "_X" if you want User selection ) ....

 

[Sorry -- I've edited this quite a few times....]

Do the above at the least, for the User selection and the malformed-list error -- other changes may also be needed, for example, is this a valid construction?

  (vla-get-blocks ss1)

Kent Cooper, AIA
Message 8 of 8
mtaras
in reply to: Kent1Cooper

Hi Kent!  thank you very much for comment. After your instructions, the code runs with out errors 🙂 Thanks to Lee Mac for his coding being so transparent, good for study even for an evergreen like me!

Further an issue here is present, as you mentioned about construction, new lisp changes all hatches within all blocks in doc, and not only within a selected block, which will take me some study again, to put effect only on selected block.

 

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

Post to forums  

Autodesk Design & Make Report

”Boost