Full automatic hatching in specific layer- AutoCAD LT

Full automatic hatching in specific layer- AutoCAD LT

infoGM8C2
Participant Participant
588 Views
4 Replies
Message 1 of 5

Full automatic hatching in specific layer- AutoCAD LT

infoGM8C2
Participant
Participant

Hello everyone,

 

Professionally i work a lot with city-plans. For each plan i have to hatch all closed polygones on the layer BGB1 at a scale of 15 and all closed polygons on layer BGB2 at a scale of 10.

Is it possible to automate this completly without any intervention?

I attached example-files, The DXF is the data and the dwg is what I should get.

Thanks in advance for all the help.

 

@infoGM8C2 - Moderation team edited title for clarity. 

0 Likes
Accepted solutions (2)
589 Views
4 Replies
Replies (4)
Message 2 of 5

Moshe-A
Mentor
Mentor
Accepted solution

@infoGM8C2  hi,

 

check this CUSHAT command

 

enjoy

Moshe

 

(vl-load-com) ; load activex support
; Custom Hatch
(defun c:cushat (/ _layers ; local function
		   LAYER&SCALE adoc ss data ename AcDbModelSpace AcDbHatch outLoop)

 ; anonymous function
 (setq _layers (lambda (lst) (substr (apply 'strcat (mapcar (function (lambda (e) (strcat "," (car e)))) lst)) 2)))

 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startUndoMark adoc) 
  
 (setq LAYER&SCALE '(("gbg1" . 15) ("gbg2" . 10))) ; may be modified with new layers & scales

 (if (setq ss (ssget "_X" (list '(0 . "polyline,lwpolyline") (cons '8 (_layers LAYER&SCALE)) '(70 . 1))))
  (progn
   (setq AcDbModelSpace (vla-get-modelSpace adoc))
   
   (foreach data LAYER&SCALE
    (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
					       
     (if (eq (strcase (cdr (assoc '8 (entget ename)))) (strcase (car data)))
      (progn
       (setq AcDbHatch (vla-addHatch AcDbModelSpace acHatchPatternTypePredefined "ansi31" :vlax-true))
       (setq outerLoop (vlax-make-safearray vlax-vbObject '(0 . 0)))
       (vlax-safearray-put-element outerLoop 0 (vlax-ename->vla-object ename))
       (vla-put-layer AcDbhatch (car data))
       (vla-put-patternScale AcDbhatch (cdr data))
       (vla-AppendOuterLoop AcDbHatch outerLoop)
       (vla-Evaluate AcDbHatch)
       (vlax-release-object AcDbHatch)
      ); progn
     ); if
					       
    ); foreach
   ); foreach

   (vlax-release-object AcDbModelSpace)
  ); progn
 ); if

 (vla-endUndoMark adoc)
 (vlax-release-object adoc)
  
 (princ)
); c:cushat

 

 

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

Correcting your "BGB" to "GBG" to agree with the Layer names in the drawing....

If you have a new-enough version of LT to be able to use AutoLisp, it can be as simple as this [lightly tested]:

 

(defun C:DOIT (/ ss)
  (foreach entry '(("GBG1" 15) ("GBG2" 10))
    (if (setq ss (ssget "_X" (list '(0 . "LWPOLYLINE") (cons 8 (car entry)) '(-4 . "&") '(70 . 1))))
      (progn ; then
        (setvar 'clayer (car entry))
        (command "_.hatch" "ANSI31" (cadr entry) 0 ss "")
      ); progn
    ); if
  ); foreach
  (prin1)
)

 

The sample drawing has only "lightweight" Polylines.  If "heavy" ones might also be included, change "LWPOLYLINE" to "*POLYLINE".

Kent Cooper, AIA
0 Likes
Message 4 of 5

pendean
Community Legend
Community Legend

@infoGM8C2Are you aware of the variables CLAYER or HPLAYER (sets the layer), HPNAME (sets the hatch pattern), and HPSCALE (sets the hatch scale) that have been around for quite some time to do what you want all this time?
And simple macro buttons (or if you must have it, a LISP) in your LT version pretty much would have gotten you there?

SYSVARMONITOR command can be used to always ensure those hatch-specific three variables are always set the way you want too https://help.autodesk.com/view/ACDLT/2025/ENU/?guid=GUID-82BACF96-AC90-446A-8E60-3CC3072F8060

Here is the full list of Hatch Pattern Variables if you wish to explore, there are some gems in there:
https://help.autodesk.com/view/ACDLT/2025/ENU/?guid=GUID-B94870E7-49CE-4BB0-A978-382A38E1FED8#:~:tex...)

HPANG (System Variable)
HPANNOTATIVE (System Variable)
HPASSOC (System Variable)
HPBACKGROUNDCOLOR (System Variable)
HPBOUND (System Variable)
HPBOUNDRETAIN (System Variable)
HPCOLOR (System Variable)
HPDLGMODE (System Variable)
HPDOUBLE (System Variable)
HPDRAWMODE (System Variable)
HPDRAWORDER (System Variable)
HPGAPTOL (System Variable)
HPINHERIT (System Variable)
HPISLANDDETECTION (System Variable)
HPISLANDDETECTIONMODE (System Variable)
HPLAYER (System Variable)
HPLINETYPE (System Variable)
HPMAXAREAS (System Variable)
HPMAXLINES (System Variable)
HPNAME (System Variable)
HPOBJWARNING (System Variable)
HPORIGIN (System Variable)
HPORIGINMODE (System Variable)
HPPATHALIGNMENT (System Variable)
HPPATHWIDTH (System Variable)
HPPICKMODE (System Variable)
HPQUICKPREVIEW (System Variable)
HPQUICKPREVTIMEOUT (System Variable)
HPSCALE (System Variable)
HPSEPARATE (System Variable)
HPSPACE (System Variable)
HPTRANSPARENCY (System Variable)

0 Likes
Message 5 of 5

infoGM8C2
Participant
Participant

Thanks Moshe ans Kent, both solutions work just fine. I'm very new in LISP and this should taken me a very long time to achieve this. Thank you very much.

0 Likes