You know what,
You probably need to specify smaller scale factor of hatching - it was hardcoded as "1.0", but have you tried with "0.1"...
Here is my final code, but instead of simplifying to 2 clicks it'll ask for hatch name, scale factor and rotation of hatching... Nevertheless, I'd keep latest code posted here, as it is the most user friendly and nothing is hard coded - it should ask for hatch pattern name for which I placed "ANSI31" as starting default, as BricsCAD doesn't have "STARS" in default pattern built-in list... Also because JOIN command is somewhat phallic, you should load (c:joinlsp) separately and only then perform (c:modelhatch) as (c:modelhatch) is calling (c:joinlsp)...
(defun c:joinlsp ( / *error* peditss joinss cs qaf cmd ss ssli i li lil l1 l2 lil1 lil1l s el p1 p2 p3 p4 pp pp1 pp2 sp xx ucsf )
(defun *error* ( m )
(if qaf (setvar (quote qaflags) qaf))
(if cmd (setvar (quote cmdecho) cmd))
(if m (prompt m))
(princ)
)
(defun peditss ( ss )
(if (= (strcase (getvar (quote program))) "ACAD")
(progn
(initcommandversion 2)
(vl-cmdf "_.pedit" "_m" ss)
)
(vl-cmdf "_.pedit" "_m" ss)
)
(while (< 0 (getvar (quote cmdactive)))
(vl-cmdf "")
)
)
(defun joinss ( ss )
(if (= (strcase (getvar (quote program))) "ACAD")
(progn
(initcommandversion 2)
(vl-cmdf "_.join" ss)
)
(vl-cmdf "_.join" ss)
)
(while (< 0 (getvar (quote cmdactive)))
(vl-cmdf "")
)
)
(defun cs ( s1 en / df ex fl fz in l1 l2 s2 sf vl el elpts pts p el1 xx pp ell )
(or (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil))) (vl-load-com))
(setq fz 1e-6) ;; Point comparison tolerance
(if s1
(if en
(progn
(setq s2 (ssadd)
l1 (list (vlax-curve-getstartpoint en) (vlax-curve-getendpoint en))
)
(repeat (setq in (sslength s1))
(setq en (ssname s1 (setq in (1- in)))
vl (cons (list (vlax-curve-getstartpoint en) (vlax-curve-getendpoint en) en) vl)
)
)
(while
(progn
(foreach v vl
(if (vl-some (function (lambda ( p ) (or (equal (car v) p fz) (equal (cadr v) p fz)))) l1)
(setq s2 (ssadd (caddr v) s2)
l1 (vl-list* (car v) (cadr v) l1)
fl t
)
(setq l2 (cons v l2))
)
)
fl
)
(setq vl l2 l2 nil fl nil)
)
)
)
)
(setq el (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex s2))))
(setq elpts (mapcar (function (lambda ( x ) (list (vlax-curve-getstartpoint x) (vlax-curve-getendpoint x) x))) el))
(setq pts (mapcar (function (lambda ( x ) (list (vlax-curve-getstartpoint x) (vlax-curve-getendpoint x)))) el))
(setq p (vl-some (function (lambda ( x ) (if (= (length (vl-remove-if (function (lambda ( y ) (equal x y fz))) (apply (function append) pts))) (1- (length (apply (function append) pts)))) x))) (apply (function append) pts)))
(if (not p)
(setq p (caar elpts))
)
(setq el1 (vl-some (function (lambda ( x ) (if (vl-member-if (function (lambda ( y ) (equal p y fz))) x) x))) elpts))
(setq elpts (vl-remove el1 elpts))
(setq elpts (cons el1 elpts))
(while (setq xx (car elpts))
(setq ell (cons (caddr xx) ell))
(setq elpts (vl-remove xx elpts))
(setq pp (car (vl-remove-if (function (lambda ( x ) (equal x p fz))) (reverse (cdr (reverse xx))))))
(setq el1 (vl-some (function (lambda ( x ) (if (vl-member-if (function (lambda ( y ) (equal pp y fz))) x) x))) elpts))
(if el1
(progn
(setq elpts (vl-remove el1 elpts))
(setq elpts (cons el1 elpts))
)
)
(setq p pp)
)
ell
)
(setq cmd (getvar (quote cmdecho)))
(setvar (quote cmdecho) 0)
(setq qaf (getvar (quote qaflags)))
(setvar (quote qaflags) 1)
(if (setq ss (ssget "_:L-I"))
(progn
(setq ssli (ssget "_P" (list (cons 0 "LINE,ARC,CIRCLE,*POLYLINE,SPLINE,ELLIPSE,HELIX"))))
(repeat (setq i (sslength ssli))
(setq li (ssname ssli (setq i (1- i))))
(setq lil (cons li lil))
)
(while (setq l1 (car lil))
(setq lil1 (cs ssli l1))
(setq lil (vl-remove-if (function (lambda ( x ) (vl-position x lil1))) lil))
(setq lil1l (cons lil1 lil1l))
)
(foreach lil1 lil1l
(setq s (ssadd))
(foreach li lil1
(ssadd li s)
(ssdel li ss)
)
(cond
( (and (> (sslength s) 1) (vl-every (function (lambda ( x ) (= (cdr (assoc 0 (entget x))) "LINE"))) (setq el (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex s))))))
(setq el (mapcar (function (lambda ( a b ) (list a b))) el (cdr el)))
(while (and (setq xx (car el)) (not ucsf))
(setq l1 (car xx) l2 (cadr xx))
(setq p1 (cdr (assoc 10 (entget l1))) p2 (cdr (assoc 11 (entget l1))))
(setq p3 (cdr (assoc 10 (entget l2))) p4 (cdr (assoc 11 (entget l2))))
(cond
( (equal p1 p3 1e-6)
(setq pp p1 pp1 p2 pp2 p4)
)
( (equal p1 p4 1e-6)
(setq pp p1 pp1 p2 pp2 p3)
)
( (equal p2 p3 1e-6)
(setq pp p2 pp1 p1 pp2 p4)
)
( (equal p2 p4 1e-6)
(setq pp p2 pp1 p1 pp2 p3)
)
)
(if (not (equal (distance pp1 pp2) (+ (distance pp1 pp) (distance pp pp2)) 1e-8))
(progn
(setq ucsf t)
(vl-cmdf "_.ucs" "_3p" "_non" (trans pp1 0 1) "_non" (trans pp 0 1) "_non" (trans pp2 0 1))
)
)
(setq el (cdr el))
)
(setq el (entlast) sp (ssadd))
(peditss s)
(if (not (eq el (entlast)))
(while (setq el (entnext el))
(ssadd el sp)
)
)
(joinss sp)
(if ucsf
(progn
(setq ucsf nil)
(vl-cmdf "_.ucs" "_p")
)
)
)
( (and (> (sslength s) 1) (vl-every (function (lambda ( x ) (wcmatch (cdr (assoc 0 (entget x))) "LINE,ARC,*POLYLINE"))) (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex s)))))
(setq el (vl-remove-if-not (function (lambda ( x ) (= (cdr (assoc 0 (entget x))) "LINE"))) (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex s)))) sp (ssadd))
(foreach li el
(ssadd li sp)
(ssdel li s)
)
(setq el (entlast))
(if (> (sslength sp) 0)
(progn
(peditss sp)
(if (not (eq el (entlast)))
(while (setq el (entnext el))
(ssadd el s)
)
)
)
)
(joinss s)
)
( t
(joinss s)
)
)
)
(if (/= (sslength ss) 0)
(joinss ss)
)
)
)
(*error* nil)
)
(defun c:modelhatch ( / *error* ftoa cmd osm hpg pea 3do ucf sel sss pat ell enx elx rgs pts ori pt1 pt2 ppp ) ;;; *pat* ; *scf* ; *rot* - global variables ;;;
(or (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil))) (vl-load-com))
(defun *error* ( m )
(if ucf
(if command-s
(command-s "_.ucs" "_p")
(vl-cmdf "_.ucs" "_p")
)
)
(if (= 8 (logand 8 (getvar (quote undoctl))))
(if command-s
(command-s "_.undo" "_e")
(vl-cmdf "_.undo" "_e")
)
)
(if (getvar (quote 3dosmode))
(if 3do
(setvar (quote 3dosmode) 3do)
)
)
(if pea
(setvar (quote peditaccept) pea)
)
(if hpg
(setvar (quote hpgaptol) hpg)
)
(if osm
(setvar (quote osmode) osm)
)
(if cmd
(setvar (quote cmdecho) cmd)
)
(if m
(prompt m)
)
(princ)
)
(defun ftoa ( n / m a s b )
(if (numberp n)
(progn
(setq m (fix ((if (< n 0) - +) n 1e-8)))
(setq a (abs (- n m)))
(setq m (itoa m))
(setq s "")
(while (and (not (equal a 0.0 1e-6)) (setq b (fix (* a 10.0))))
(setq s (strcat s (itoa b)))
(setq a (- (* a 10.0) b))
)
(if (= (type n) (quote int))
m
(if (= s "")
m
(if (and (= m "0") (< n 0))
(strcat "-" m "." s)
(strcat m "." s)
)
)
)
)
)
)
(setq cmd (getvar (quote cmdecho)))
(setvar (quote cmdecho) 0)
(setq osm (getvar (quote osmode)))
(setvar (quote osmode) 0)
(setq hpg (getvar (quote hpgaptol)))
(setvar (quote hpgaptol) 1)
(setq pea (getvar (quote peditaccept)))
(setvar (quote peditaccept) 1)
(if (getvar (quote 3dosmode))
(progn
(setq 3do (getvar (quote 3dosmode)))
(setvar (quote 3dosmode) 8)
)
)
(if (= 8 (logand 8 (getvar (quote undoctl))))
(vl-cmdf "_.undo" "_e")
)
(vl-cmdf "_.undo" "_be")
(if (= 0 (getvar (quote worlducs)))
(progn
(vl-cmdf "_.ucs" "_w")
(setq ucf t)
)
)
(prompt "\nPick 3DSOLID for hatching...")
(if (setq sel (ssget "_+.:E:S:L" (list (cons 0 "3DSOLID"))))
(progn
(setq pat (getstring (strcat "\nChoose hatch pattern <" (setq *pat* (if (not *pat*) "ANSI31" *pat*)) "> : ")))
(if (= "" pat)
(setq pat *pat*)
(setq *pat* pat)
)
(initget 6)
(setq *scf* (cond ( (getreal (strcat "\nSpecify scale factor for hatching <" (ftoa (setq *scf* (if (not *scf*) 1.0 *scf*))) "> : ")) ) ( t *scf* )))
(initget 4)
(setq *rot* (cond ( (getreal (strcat "\nSpecify rotation of hatch <" (ftoa (setq *rot* (if (not *rot*) 0.0 *rot*))) "> : ")) ) ( t *rot* )))
(initget 1)
(setq ppp (getpoint "\nPick or specify point on plane you wish to hatch - only when small blue circle appears... : "))
(vl-cmdf "_.isolateobjects" sel)
(while (< 0 (getvar (quote cmdactive)))
(vl-cmdf "")
)
(setq ent (ssname sel 0))
(vl-cmdf "_.copy" ent "" (list 0.0 0.0 0.0) (list 0.0 0.0 0.0))
(setq ell (entlast))
(vl-cmdf "_.explode" "_l")
(while (< 0 (getvar (quote cmdactive)))
(vl-cmdf "")
)
(while (setq ell (entnext ell))
(if (= (cdr (assoc 0 (setq enx (entget ell)))) "REGION")
(setq rgs (cons ell rgs))
(if (or (= (cdr (assoc 0 enx)) "SURFACE") (= (cdr (assoc 0 enx)) "BODY"))
(entdel ell)
)
)
)
(foreach ell rgs
(setq elx (entlast))
(vl-cmdf "_.explode" ell)
(while (< 0 (getvar (quote cmdactive)))
(vl-cmdf "")
)
(setq sss (ssadd))
(while (setq elx (entnext elx))
(ssadd elx sss)
)
(foreach ent (vl-remove-if (function listp) (mapcar (function cadr) (ssnamex sss)))
(if (or (= (cdr (assoc 0 (setq enx (entget ent)))) "CIRCLE") (and (= (cdr (assoc 0 enx)) "ELLIPSE") (equal (cdr (assoc 42 enx)) (* 2 pi) 1e-14)))
(setq ori (vlax-curve-getstartpoint ent) pt1 (vlax-curve-getpointatparam ent (+ (vlax-curve-getstartparam ent) (/ (- (vlax-curve-getendparam ent) (vlax-curve-getstartparam ent)) 3.0))) pt2 (vlax-curve-getpointatparam ent (+ (vlax-curve-getstartparam ent) (* 2.0 (/ (- (vlax-curve-getendparam ent) (vlax-curve-getstartparam ent)) 3.0)))))
(setq pts (cons (list (vlax-curve-getstartpoint ent) (vlax-curve-getpointatparam ent (+ (vlax-curve-getstartparam ent) (/ (- (vlax-curve-getendparam ent) (vlax-curve-getstartparam ent)) 2.0)))) pts))
)
)
(if pts
(progn
(setq ori (caar pts))
(setq pt1 (cadar pts))
(setq pt2 (cadadr pts))
)
)
(if (and ori pt1 pt2 (not (equal ori pt1 1e-6)) (not (equal ori pt2 1e-6)) (not (equal pt1 pt2 1e-6)))
(progn
(vl-cmdf "_.ucs" "_3p" "_non" ori "_non" pt1 "_non" pt2)
(sssetfirst nil sss)
(c:joinlsp)
(while (< 0 (getvar (quote cmdactive)))
(vl-cmdf "")
)
(setq elx (entlast))
(if (equal (caddr (trans ppp 0 1)) 0.0 1e-6)
(progn
(vl-cmdf "_.-hatch" "_s" elx "" "_p" pat *scf* *rot*)
(while (< 0 (getvar (quote cmdactive)))
(vl-cmdf "")
)
)
)
(if (and elx (not (vlax-erased-p elx)))
(entdel elx)
)
(setq pts nil ori nil pt1 nil pt2 nil)
(vl-cmdf "_.ucs" "_p")
)
)
)
(vl-cmdf "_.unisolateobjects")
)
)
(*error* nil)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)