Also, another cheat, but this time very quick generation of pattern... This version uses dot approximation of line entities... Hatch pattern is somewhat smaller (51 points per line - instead of previously 481 lines per 247 line each)... If you zoom only too much, you can see dots, but if you are with zoomings like 4x4 rectangular boundary - you'll see sign of superman like it was drawn linearily...
So here is mod. of Lanny Schiele code :
;;;CADALYST 10/05 Tip 2065: HatchMaker.lsp Hatch Maker (c) 2005 Larry Schiele
;;;* ====== B E G I N C O D E N O W ======
;;;* HatchMaker.lsp written by Lanny Schiele at TMI Systems Design Corporation
;;;* Lanny.Schiele@tmisystems.com
;;;* Tested on AutoCAD 2002 & 2006. -- does include a 'VL' function -- should work on Acad2000 on up.
;;;
;;;* Modified by M.R. to make hatchings with points that follow lines to make hatchings acceptable for rectangular boundary.
(defun C:SaveHatch-rectangle
( / round dxf ListToFile
SelSet SelSetSize ssNth fuzz
Ent EntInfo EntType pt1 pt2
Dist a DeltaX DeltaY
DimZin lw minp maxp
ww hh pt k n dx
)
;;;* BEGIN NESTED FUNCTIONS
(defun round (num)
(if (>= (- num (fix num)) 0.5)
(fix (1+ num))
(fix num)
)
)
(defun dxf (code EnameOrElist / VarType)
(setq VarType (type EnameOrElist))
(if (= VarType (read "ENAME"))
(cdr (assoc code (entget EnameOrElist)))
(cdr (assoc code EnameOrElist))
)
)
(defun ListToFile (TextList FileName DoOpenWithNotepad AsAppend / TextItem File RetVal)
(if (setq File (open FileName (if AsAppend "a" "w")))
(progn
(foreach TextItem TextList
(write-line TextItem File)
)
(setq File (close File))
(if DoOpenWithNotepad
(startapp "notepad" FileName)
)
)
)
(FindFile FileName)
)
(textscr)
(getstring "\nHit [ENTER] to continue...")
(princ "\nSelect pattern of lines and/or points for new hatch pattern along with bounding lwpolyline boundary...")
(while (not (setq SelSet (ssget (list (cons -4 "<or") (cons 0 "LINE,POINT") (cons -4 "<and") (cons 0 "LWPOLYLINE") (cons 90 4) (cons -4 "&=") (cons 70 1) (cons -4 "<not") (cons -4 "<>") (cons 42 0.0) (cons -4 "not>") (cons -4 "and>") (cons -4 "or>"))))))
(initget 6)
(setq fuzz (cond ( (getdist "\nPick or specify fuzz distance between 2 adjacent points <0.005> : ") ) (0.005)))
(foreach o (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex SelSet)))
(if (= (cdr (assoc 0 (entget o))) "LWPOLYLINE")
(setq lw o)
)
)
(ssdel lw SelSet)
(vla-getboundingbox (vlax-ename->vla-object lw) (quote minp) (quote maxp))
(mapcar (function set) (list (quote minp) (quote maxp)) (mapcar (function safearray-value) (list minp maxp)))
(setq ww (- (car maxp) (car minp)) hh (- (cadr maxp) (cadr minp)))
(setq ssNth 0
SelSetSize (sslength SelSet)
DimZin (getvar "DIMZIN")
)
(setvar "DIMZIN" 11)
(if (> SelSetSize 0)
(princ "\nAnalyaing entities...")
)
(while (< ssNth SelSetSize)
(setq Ent (ssname SelSet ssNth)
EntInfo (entget Ent)
EntType (dxf 0 EntInfo)
ssNth (+ ssNth 1)
)
(cond
( (= EntType "POINT")
(setq pt1 (dxf 10 EntInfo)
FileLine (strcat "0," (rtos (car pt1) 2 8) "," (rtos (cadr pt1) 2 8) "," (rtos ww 2 8) "," (rtos hh 2 8) ",0,-" (rtos ww 2 8))
)
(princ (strcat "\n" FileLine))
(setq FileLines (cons FileLine FileLines))
)
( (= EntType "LINE")
(setq pt1 (dxf 10 EntInfo)
pt2 (dxf 11 EntInfo)
Dist (distance pt1 pt2)
a (angle pt1 pt2)
)
(setq n (fix (/ Dist fuzz)))
(if (= n 0)
(setq n 1)
)
(setq dx (/ Dist n))
(setq k -1)
(repeat (1+ n)
(setq k (1+ k))
(setq pt (polar pt1 a (* dx k)))
(setq FileLine (strcat "0," (rtos (car pt) 2 8) "," (rtos (cadr pt) 2 8) "," (rtos ww 2 8) "," (rtos hh 2 8) ",0,-" (rtos ww 2 8)))
(setq FileLines (cons FileLine FileLines))
)
)
( (princ (strcat "\n * * * Invalid entity " EntType " omitted."))
)
)
)
(setvar "DIMZIN" DimZin)
(if
(and
FileLines
(setq HatchDescr (getstring T "\nBriefly describe this hatch pattern: "))
(setq FileName (getfiled "Hatch Pattern File" (strcat (getvar (quote roamablerootprefix)) "support\\") "pat" 1))
)
(progn
(if (= HatchDescr "")
(setq HatchDescr "Custom hatch pattern")
)
(setq HatchName (vl-filename-base FileName)
FileLines (cons (strcat "*" HatchName "," HatchDescr) (reverse FileLines))
)
(princ "\n============================================================")
(princ (strcat "\nPlease wait while the hatch file is created...\n"))
(ListToFile FileLines FileName nil nil)
(while (not (findfile FileName))) ; (vl-cmdf "delay" 1500) ; delay required so file can be created and found (silly, but req.)
(if (findfile FileName)
(princ (strcat "\nHatch pattern '" HatchName "' is ready to use!"))
(progn
(princ "\nUnable to create hatch pattern file:")
(princ (strcat "\n " FileName))
)
)
)
(princ (if FileLines "\nCancelled." "\nUnable to create hatch pattern from selected entities."))
)
(princ)
)
;|
(princ "\n ************************************************************** ")
(princ "\n** **")
(princ "\n* HatchMaker.lsp written by Lanny Schiele -- enjoy! *")
(princ "\n* *")
(princ "\n* Type in DRAWHATCH to have the environment created to draw. *")
(princ "\n* Type in SAVEHATCH to save the pattern you created. *")
(princ "\n** **")
(princ "\n ************************************************************** ")
(princ)
|;
sups-rec-hatched-4x4.dwg
sups-rec.pat