Alex, I don't think BOUNDARY command was written using Vanilla/Visual Lisp only... I made some attempts in LISP and although it's poor implementation, I'll post it here in ALISP forum... I am also interested to see if someone will reply and have some opinion... My method is using RAY entity and I don't think that was used in real BOUNDARY algorithm... And yes it's not good at all, but with some simple case it may solve, but only in simple situation with some ordinary entities surrounding picked internal point... What to say - I realized that I can't do it easy so you're right it's challenge for some more advanced programming...
(defun c:bndr ( / *error* unit *adoc* pea pck ss p i1 c1 i2 c2 ip ipl trl s el sx ii pl tt ttt trr trx trxx )
(vl-load-com)
(defun *error* ( m )
(if pea
(setvar 'peditaccept pea)
)
(if pck
(setvar 'pickbox pck)
)
(vla-endundomark *adoc*)
(if m
(prompt m)
)
(princ)
)
(defun unit ( v )
(if (not (equal v '(0.0 0.0 0.0) 1e-6))
(mapcar '(lambda ( x ) (/ x (distance '(0.0 0.0 0.0) v))) v)
)
)
(vla-startundomark (setq *adoc* (vla-get-activedocument (vlax-get-acad-object))))
(setq pea (getvar 'peditaccept))
(setvar 'peditaccept 1)
(setq pck (getvar 'pickbox))
(prompt "\nSelect boundary curve entities...")
(setq ss (ssget "_:L" '((0 . "*POLYLINE,LINE,SPLINE,ARC,CIRCLE,ELLIPSE"))))
(while (not ss)
(prompt "\nSource curve boundary sel. set empty... Please reselect boundary curves on unlocked layer(s) again...")
(setq ss (ssget "_:L" '((0 . "*POLYLINE,LINE,SPLINE,ARC,CIRCLE,ELLIPSE"))))
)
(initget 1)
(setq p (getpoint "\nPick or specify internal point : "))
(setvar 'pickbox 4)
(repeat (setq i1 (sslength ss))
(setq c1 (ssname ss (setq i1 (1- i1))))
(ssdel c1 ss)
(repeat (setq i2 (sslength ss))
(setq c2 (ssname ss (setq i2 (1- i2))))
(setq ip (vlax-invoke (vlax-ename->vla-object c1) 'intersectwith (vlax-ename->vla-object c2) acextendnone))
(if ip
(repeat (/ (length ip) 3)
(setq ipl (cons (list (car ip) (cadr ip) (caddr ip)) ipl))
(setq ip (cdddr ip))
)
)
)
(setq ipl (vl-sort ipl '(lambda ( a b ) (< (vlax-curve-getparamatpoint c1 a) (vlax-curve-getparamatpoint c1 b)))))
(mapcar
'(lambda ( a b / ray ipp ippl v )
(setq v (unit (mapcar '- (vlax-curve-getpointatparam c1 (/ (+ (vlax-curve-getparamatpoint c1 a) (vlax-curve-getparamatpoint c1 b)) 2.0)) p)))
(setq ray (entmakex (list '(0 . "RAY") '(100 . "AcDbEntity") '(100 . "AcDbRay") (cons 10 p) (cons 11 v))))
(setq ipp (vlax-invoke (vlax-ename->vla-object ray) 'intersectwith (vlax-ename->vla-object c1) acextendnone))
(repeat (setq i2 (sslength ss))
(setq c2 (ssname ss (setq i2 (1- i2))))
(setq ipp (append (vlax-invoke (vlax-ename->vla-object ray) 'intersectwith (vlax-ename->vla-object c2) acextendnone) ipp))
)
(if ipp
(repeat (/ (length ipp) 3)
(setq ippl (cons (list (car ipp) (cadr ipp) (caddr ipp)) ippl))
(setq ipp (cdddr ipp))
)
)
(if (vlax-curve-getparamatpoint c1 (car (setq ippl (vl-sort ippl '(lambda ( a b ) (< (vlax-curve-getparamatpoint ray a) (vlax-curve-getparamatpoint ray b)))))))
(progn
(if (not (vl-position (list a c1 b) trl))
(setq trl (cons (list a c1 b) trl))
)
;|
(if (cadr ippl)
(foreach ipp (cdr ippl)
(setq pl (cons ipp pl))
)
)
|;
)
(if
(and
(vlax-curve-getparamatpoint (ssname (ssdel ray (ssget "_C" (car ippl) (car ippl))) 0) a)
(vlax-curve-getparamatpoint (ssname (ssdel ray (ssget "_C" (car ippl) (car ippl))) 0) b)
(not (vl-position (list a (ssname (ssdel ray (ssget "_C" (car ippl) (car ippl))) 0) b) trl))
)
(setq trl (cons (list a (ssname (ssdel ray (ssget "_C" (car ippl) (car ippl))) 0) b) trl))
)
)
(entdel ray)
)
ipl
(cdr ipl)
)
(setq ipl nil)
(ssadd c1 ss)
)
;|
(foreach p pl
(vl-some '(lambda ( x ) (if (< (vlax-curve-getparamatpoint (cadr x) (car x)) (vlax-curve-getparamatpoint (cadr x) p) (vlax-curve-getparamatpoint (cadr x) (caddr x))) (setq tr x) (setq tr nil))) trl)
(if tr
(setq trl (vl-remove tr trl))
)
(setq tr nil)
)
|;
;|
(foreach tr trl
(setq trx (vl-remove-if-not '(lambda ( x ) (eq (cadr tr) (cadr x))) trl))
(if (> (length trx) 1)
(progn
(foreach tt trx
(setq trl (vl-remove tt trl))
)
(setq trr trx)
(while (setq tt (car trx))
(setq ttt (cadr trx))
(if (equal (last tt) (car ttt) 1e-6)
(setq trxx (cons (list (car tt) (cadr tt) (caddr ttt)) trxx))
)
(setq trx (cdr trx))
)
(setq trxx (reverse trxx))
(setq trr (vl-remove-if '(lambda ( x ) (vl-some '(lambda ( y ) (or (equal (caddr y) (car x) 1e-6) (equal (car y) (caddr x) 1e-6))) trr)) trr))
(foreach tt trxx
(setq trr (cons tt trr))
)
(foreach tt trr
(setq trl (cons tt trl))
)
)
)
)
|;
(foreach tr trl
(repeat (1- (length (vl-remove-if-not '(lambda ( x ) (eq (cadr tr) (cadr x))) trl)))
(setq trl (subst (list (car tr) (vlax-vla-object->ename (vla-copy (vlax-ename->vla-object (cadr tr)))) (caddr tr) t) tr trl))
)
)
(foreach tr trl
(if (eq (last tr) t)
(entdel (cadr tr))
)
)
(setq s (ssadd))
(foreach tr (vl-remove-if '(lambda ( x ) (eq (last x) t)) trl)
(setq el (entlast))
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (cadr tr) (vlax-curve-getpointatparam (cadr tr) (if (> (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.1) (- (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.1) (if (> (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.01) (- (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.01) (if (> (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.001) (- (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.001)))))) 0 1) "")
(cond
( (and
(vlax-curve-getparamatpoint (entlast) (caddr tr))
(not
(or
(equal (vlax-curve-getstartpoint (entlast)) (car tr) 1e-6)
(equal (vlax-curve-getendpoint (entlast)) (car tr) 1e-6)
)
)
)
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (entlast) (vlax-curve-getpointatparam (entlast) (if (< (vlax-curve-getparamatpoint (entlast) (caddr tr)) (vlax-curve-getparamatpoint (entlast) (car tr))) (vlax-curve-getendparam (entlast)) (vlax-curve-getstartparam (entlast))))) 0 1) "")
)
( (and
(vlax-curve-getparamatpoint (cadr tr) (caddr tr))
(not
(or
(equal (vlax-curve-getstartpoint (cadr tr)) (car tr) 1e-6)
(equal (vlax-curve-getendpoint (cadr tr)) (car tr) 1e-6)
)
)
)
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (cadr tr) (vlax-curve-getpointatparam (cadr tr) (if (< (vlax-curve-getparamatpoint (cadr tr) (caddr tr)) (vlax-curve-getparamatpoint (cadr tr) (car tr))) (vlax-curve-getendparam (cadr tr)) (vlax-curve-getstartparam (cadr tr))))) 0 1) "")
)
)
(if (not (and (vlax-curve-getparamatpoint (entlast) (car tr)) (vlax-curve-getparamatpoint (entlast) (caddr tr))))
(progn
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (cadr tr) (vlax-curve-getpointatparam (cadr tr) (if (> (- (vlax-curve-getendparam (cadr tr)) (vlax-curve-getparamatpoint (cadr tr) (caddr tr))) 0.1) (+ (vlax-curve-getparamatpoint (cadr tr) (caddr tr)) 0.1) (if (> (- (vlax-curve-getendparam (cadr tr)) (vlax-curve-getparamatpoint (cadr tr) (caddr tr))) 0.01) (+ (vlax-curve-getparamatpoint (cadr tr) (caddr tr)) 0.01) (if (> (- (vlax-curve-getendparam (cadr tr)) (vlax-curve-getparamatpoint (cadr tr) (caddr tr))) 0.001) (+ (vlax-curve-getparamatpoint (cadr tr) (caddr tr)) 0.001)))))) 0 1) "")
(if (and (vlax-curve-getparamatpoint (entlast) (car tr)) (vlax-curve-getparamatpoint (entlast) (caddr tr)))
(ssadd (entlast) s)
(if (not (eq el (entlast)))
(progn
(entdel (entlast))
(ssadd (cadr tr) s)
)
(ssadd (cadr tr) s)
)
)
)
(progn
(if (not (eq (cadr tr) (entlast)))
(entdel (cadr tr))
)
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (entlast) (vlax-curve-getpointatparam (entlast) (if (> (- (vlax-curve-getendparam (entlast)) (vlax-curve-getparamatpoint (entlast) (caddr tr))) 0.1) (+ (vlax-curve-getparamatpoint (entlast) (caddr tr)) 0.1) (if (> (- (vlax-curve-getendparam (entlast)) (vlax-curve-getparamatpoint (entlast) (caddr tr))) 0.01) (+ (vlax-curve-getparamatpoint (entlast) (caddr tr)) 0.01) (if (> (- (vlax-curve-getendparam (entlast)) (vlax-curve-getparamatpoint (entlast) (caddr tr))) 0.001) (+ (vlax-curve-getparamatpoint (entlast) (caddr tr)) 0.001)))))) 0 1) "")
(if (and (vlax-curve-getparamatpoint (entlast) (car tr)) (vlax-curve-getparamatpoint (entlast) (caddr tr)))
(ssadd (entlast) s)
(if (not (eq el (entlast)))
(progn
(entdel (entlast))
(if (not (vlax-erased-p (cadr tr)))
(ssadd (cadr tr) s)
(progn
(setq sx (ssget "_C" (car tr) (car tr)))
(repeat (setq ii (sslength sx))
(if
(or
(and
(equal (vlax-curve-getstartpoint (ssname sx (setq ii (1- ii)))) (car tr) 1e-6)
(equal (vlax-curve-getendpoint (ssname sx ii)) (caddr tr) 1e-6)
)
(and
(equal (vlax-curve-getstartpoint (ssname sx ii)) (caddr tr) 1e-6)
(equal (vlax-curve-getendpoint (ssname sx ii)) (car tr) 1e-6)
)
)
(ssadd (ssname sx ii) s)
)
)
)
)
)
(if (not (vlax-erased-p (cadr tr)))
(ssadd (cadr tr) s)
(progn
(setq sx (ssget "_C" (car tr) (car tr)))
(repeat (setq ii (sslength sx))
(if
(or
(and
(equal (vlax-curve-getstartpoint (ssname sx (setq ii (1- ii)))) (car tr) 1e-6)
(equal (vlax-curve-getendpoint (ssname sx ii)) (caddr tr) 1e-6)
)
(and
(equal (vlax-curve-getstartpoint (ssname sx ii)) (caddr tr) 1e-6)
(equal (vlax-curve-getendpoint (ssname sx ii)) (car tr) 1e-6)
)
)
(ssadd (ssname sx ii) s)
)
)
)
)
)
)
)
)
)
(foreach tr (vl-remove-if-not '(lambda ( x ) (eq (last x) t)) trl)
(entdel (cadr tr))
(setq el (cadr tr))
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (cadr tr) (vlax-curve-getpointatparam (cadr tr) (if (> (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.1) (- (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.1) (if (> (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.01) (- (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.01) (if (> (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.001) (- (vlax-curve-getparamatpoint (cadr tr) (car tr)) 0.001)))))) 0 1) "")
(cond
( (and
(vlax-curve-getparamatpoint (entlast) (caddr tr))
(not
(or
(equal (vlax-curve-getstartpoint (entlast)) (car tr) 1e-6)
(equal (vlax-curve-getendpoint (entlast)) (car tr) 1e-6)
)
)
)
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (entlast) (vlax-curve-getpointatparam (entlast) (if (< (vlax-curve-getparamatpoint (entlast) (caddr tr)) (vlax-curve-getparamatpoint (entlast) (car tr))) (vlax-curve-getendparam (entlast)) (vlax-curve-getstartparam (entlast))))) 0 1) "")
)
( (and
(vlax-curve-getparamatpoint (cadr tr) (caddr tr))
(not
(or
(equal (vlax-curve-getstartpoint (cadr tr)) (car tr) 1e-6)
(equal (vlax-curve-getendpoint (cadr tr)) (car tr) 1e-6)
)
)
)
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (cadr tr) (vlax-curve-getpointatparam (cadr tr) (if (< (vlax-curve-getparamatpoint (cadr tr) (caddr tr)) (vlax-curve-getparamatpoint (cadr tr) (car tr))) (vlax-curve-getendparam (cadr tr)) (vlax-curve-getstartparam (cadr tr))))) 0 1) "")
)
)
(if (not (and (vlax-curve-getparamatpoint (entlast) (car tr)) (vlax-curve-getparamatpoint (entlast) (caddr tr))))
(progn
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (cadr tr) (vlax-curve-getpointatparam (cadr tr) (if (> (- (vlax-curve-getendparam (cadr tr)) (vlax-curve-getparamatpoint (cadr tr) (caddr tr))) 0.1) (+ (vlax-curve-getparamatpoint (cadr tr) (caddr tr)) 0.1) (if (> (- (vlax-curve-getendparam (cadr tr)) (vlax-curve-getparamatpoint (cadr tr) (caddr tr))) 0.01) (+ (vlax-curve-getparamatpoint (cadr tr) (caddr tr)) 0.01) (if (> (- (vlax-curve-getendparam (cadr tr)) (vlax-curve-getparamatpoint (cadr tr) (caddr tr))) 0.001) (+ (vlax-curve-getparamatpoint (cadr tr) (caddr tr)) 0.001)))))) 0 1) "")
(if (and (vlax-curve-getparamatpoint (entlast) (car tr)) (vlax-curve-getparamatpoint (entlast) (caddr tr)))
(ssadd (entlast) s)
(if (not (eq el (entlast)))
(progn
(entdel (entlast))
(ssadd (cadr tr) s)
)
(ssadd (cadr tr) s)
)
)
)
(progn
(if (not (eq (cadr tr) (entlast)))
(entdel (cadr tr))
)
(command "_.TRIM" "" "_nea" (trans (vlax-curve-getclosestpointto (entlast) (vlax-curve-getpointatparam (entlast) (if (> (- (vlax-curve-getendparam (entlast)) (vlax-curve-getparamatpoint (entlast) (caddr tr))) 0.1) (+ (vlax-curve-getparamatpoint (entlast) (caddr tr)) 0.1) (if (> (- (vlax-curve-getendparam (entlast)) (vlax-curve-getparamatpoint (entlast) (caddr tr))) 0.01) (+ (vlax-curve-getparamatpoint (entlast) (caddr tr)) 0.01) (if (> (- (vlax-curve-getendparam (entlast)) (vlax-curve-getparamatpoint (entlast) (caddr tr))) 0.001) (+ (vlax-curve-getparamatpoint (entlast) (caddr tr)) 0.001)))))) 0 1) "")
(if (and (vlax-curve-getparamatpoint (entlast) (car tr)) (vlax-curve-getparamatpoint (entlast) (caddr tr)))
(ssadd (entlast) s)
(if (not (eq el (entlast)))
(progn
(entdel (entlast))
(if (not (vlax-erased-p (cadr tr)))
(ssadd (cadr tr) s)
(progn
(setq sx (ssget "_C" (car tr) (car tr)))
(repeat (setq ii (sslength sx))
(if
(or
(and
(equal (vlax-curve-getstartpoint (ssname sx (setq ii (1- ii)))) (car tr) 1e-6)
(equal (vlax-curve-getendpoint (ssname sx ii)) (caddr tr) 1e-6)
)
(and
(equal (vlax-curve-getstartpoint (ssname sx ii)) (caddr tr) 1e-6)
(equal (vlax-curve-getendpoint (ssname sx ii)) (car tr) 1e-6)
)
)
(ssadd (ssname sx ii) s)
)
)
)
)
)
(if (not (vlax-erased-p (cadr tr)))
(ssadd (cadr tr) s)
(progn
(setq sx (ssget "_C" (car tr) (car tr)))
(repeat (setq ii (sslength sx))
(if
(or
(and
(equal (vlax-curve-getstartpoint (ssname sx (setq ii (1- ii)))) (car tr) 1e-6)
(equal (vlax-curve-getendpoint (ssname sx ii)) (caddr tr) 1e-6)
)
(and
(equal (vlax-curve-getstartpoint (ssname sx ii)) (caddr tr) 1e-6)
(equal (vlax-curve-getendpoint (ssname sx ii)) (car tr) 1e-6)
)
)
(ssadd (ssname sx ii) s)
)
)
)
)
)
)
)
)
)
;;; (command "_.JOIN" (ssname s 0) s "") - JOIN command variant looks better but CAD can't do it good...
(command "_.PEDIT" "_M" s "" "_J" "_J" "_E" 0.0)
(while (< 0 (getvar 'cmdactive))
(command "")
)
;;; PEDIT JOIN command for generating LWPOLYLINE as result, more stupid version, but CAD can handle it better...
(command "_.COPYBASE" "_non" '(0.0 0.0 0.0) (if (not (vlax-erased-p (ssname s 0))) (ssname s 0) (entlast)) "")
(command "_.UNDO" "_B")
(command "_.PASTECLIP" "_non" '(0.0 0.0 0.0))
(sssetfirst nil (ssadd (entlast)))
(*error* nil)
)
HTH, M.R.
Regards...
Marko Ribar, d.i.a. (graduated engineer of architecture)