lisp from hatch solid to hatch ansi31

lisp from hatch solid to hatch ansi31

dvir860
Enthusiast Enthusiast
960 Views
4 Replies
Message 1 of 5

lisp from hatch solid to hatch ansi31

dvir860
Enthusiast
Enthusiast

I have a lisp that makes Hatch Solid to Hatch ansi31.
In the lisp, I must choose the Hatch Solid to lisp changes the Hatch ansi31.
What should I do to that the lisp automatically work on all Hatch Solid in the draw without the need of the user's choice?

 

The lisp:

 

(defun c:2ansi31 (/ ss)
(cond ((not acdoc)
(setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
)
)
(if (setq ss (ssget "_:L" '((0 . "HATCH") (2 . "~ansi31"))))
(progn
(vla-StartUndoMark acdoc)
((lambda (i / sn)
(while
(setq sn (ssname ss (setq i (1+ i))))
(vla-setPattern
(vlax-ename->vla-object sn)
acHatchPatternTypePreDefined
"ansi31"
)
)
)
-1
)
(vla-EndUndoMark acdoc)
)
(princ)
)
(princ)
)

 

 

Dvir.

0 Likes
961 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

Hi, try this code. Change parameter of (ssget) from :L to "_A"... and by adding (cons 410 (getvar 'ctab)) you will limit the all selection only to current model or layout.

 

(defun c:2ansi31 (/ ss)
  (cond ((not acdoc)
	 (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
	 )
	)
  (if (setq ss (ssget "_A" (list '(0 . "HATCH")
				 '(2 . "~ansi31")
				 (cons 410 (getvar 'CTAB))
				 )))
    (progn
      (vla-StartUndoMark acdoc)
      ((lambda (i / sn)
	 (while
	   (setq sn (ssname ss (setq i (1+ i))))
	   (vla-setPattern
	     (vlax-ename->vla-object sn)
	     acHatchPatternTypePreDefined
	     "ansi31"
	     )
	   )
	 )
	-1
	)
      (vla-EndUndoMark acdoc)
      )
    (princ)
    )
  (princ)
)
0 Likes
Message 3 of 5

dvir860
Enthusiast
Enthusiast

How do I change the code so that Lisp will also work on hatch within blocks?
Is there a way to control the scale through lisp?

0 Likes
Message 4 of 5

hmsilva
Mentor
Mentor

@dvir860 wrote:

How do I change the code so that Lisp will also work on hatch within blocks?
Is there a way to control the scale through lisp?


Something like this, perhaps...

 

(vl-load-com)
(defun c:demo nil
    (or acdoc (setq acdoc (vla-get-activedocument (vlax-get-acad-object))))
    (vla-StartUndoMark acdoc)
    (vlax-for blks (vla-get-blocks acdoc)
        (if (= (vla-get-isxref blks) :vlax-false)
            (vlax-for blk blks
                (if (and (= (vla-get-objectname blk) "AcDbHatch")
                         (/= (vla-get-patternname blk) "ANSI31")
                         (vlax-write-enabled-p blk)
                    )
                    (progn
                        (vla-setPattern blk acHatchPatternTypePreDefined "ANSI31")
                        (vla-put-patternscale blk 1.0)
                    )
                )
            )
        )
    )
    (vla-regen acdoc acallviewports)
    (vla-EndUndoMark acdoc)
    (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 5 of 5

Kent1Cooper
Consultant
Consultant

@dvir860 wrote:

I have a lisp that makes Hatch Solid to Hatch ansi31.
....


It looks to me as though the original routine and both suggested changes would not do what you describe, but would change all Hatch objects that are not already in the ANSI31 pattern to be ANSI31.  If that's really what you want to do, you don't need to check for the pattern name at all, either in filtering the selection [Posts 1 & 2] or in checking for the pattern while stepping through objects [Post 4].  You could just find all Hatch objects, and force them all to be ANSI31, regardless of what their current pattern is.  That would be considerably simpler.

 

If you really want to change only those that are SOLID to ANSI31, then any of those routines should be looking not for whether a Hatch object's pattern is not ANSI31, but whether it is SOLID.

Kent Cooper, AIA
0 Likes