Jump to content

Add user selection (lisp to change pattern of solid hatchs )


PedroT

Recommended Posts

Hello!

 

I've been using a lisp from Lee Mac that changes all solid hatch to other predefined pattern (a big thanks to him although I'm a silent user of his work, original post here). 

 

The lisp changes all hatch, including those in locked layers and both on model and paperspace.

 

I've made a few minor changes (ask for scale) but I would link to ask for a selection set and don't have the knowledge for it. I guess it's probably simple, and if so can you guys help on this?

 

(defun c:HHS ( / doc escala)

   (setq escala (getreal "\nEnter scale for ANSI31 hatch: "))

   (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))
                       (= "SOLID" (strcase (vla-get-patternname obj)))
                       (vlax-write-enabled-p obj)
                   )
                   (progn
                       (vla-setpattern obj achatchpatterntypepredefined "ANSI31")
                       (vla-put-patternscale obj escala)
                   )
               )
           )
       )
   )
   (vla-regen doc acallviewports)
   (princ)
)
(vl-load-com) (princ)

 

Cheers,

Pedro T.

 

Link to comment
Share on other sites

If you mean select a hatch and change its pattern across a selection then something like this.

 

(defun c:wow ( / ss obj x)
(prompt "\nSelect hatches ")
(setq ss (ssget '((0 . "HATCH")( 2 . "SOLID"))))
(if (= ss nil)
(alert "no hatches selected\n\nWill exit")
(progn
(setq escala (getreal "\nEnter scale for ANSI31 hatch: "))
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
 (vla-setpattern obj achatchpatterntypepredefined "ANSI31")
 (vla-put-patternscale obj escala)
)
)
)
(princ)
)
(c:wow)

 

Link to comment
Share on other sites

On 11/19/2023 at 1:33 AM, BIGAL said:

If you mean select a hatch and change its pattern across a selection then something like this.

 

 

 

Thanks so much Bigal that works great (I had to delete the last line, tho).

 

Would it be possible to change hatch within blocks also?

 

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