Here is an alternative, using grdraw:
- (defun c:test ( / *error* enl enx lst ply pnt ) (defun *error* ( msg ) (if (and (= 'ename (type ply)) (entget ply)) (entdel ply)) (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) (princ (strcat "\nError: " msg)) ) (redraw) (grtext) (princ) ) (while (setq pnt (getpoint "\nPick a point within a closed boundary : ")) (redraw) (setq enl (entlast)) (vl-cmdf "_.-boundary" "_A" "_I" "_N" "" "_O" "_P" "" "_non" pnt "") (if (and (not (eq enl (setq ply (entlast)))) (setq enx (entget ply)) (= "LWPOLYLINE" (cdr (assoc 0 enx))) (= 1 (logand 1 (cdr (assoc 70 enx)))) ) (progn (mapcar '(lambda ( a b ) (grdraw a b 3 1)) (setq lst (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx))) (cons (last lst) lst) ) (LM:polywipeout lst) (grtext -1 (strcat "Enclosed area: " (rtos (vlax-curve-getarea ply) 2 0) " m2")) (entdel ply) ) (princ "\nNo valid boundary found.") ) ) (redraw) (grtext) (princ));; Polygonal Wipeout - Lee Mac;; Constructs a polygonal wipeout with vertices positioned at the supplied coordinates.;; l - [lst] List of wipeout vertices (UCS)(defun LM:polywipeout ( l / c m p ) (setq l (cons (last l) l) p (apply 'mapcar (cons 'min l)) m (apply 'max (mapcar '- (apply 'mapcar (cons 'max l)) p)) c (mapcar '+ p (list (/ m 2.0) (/ m 2.0))) ) (entmakex (append (list '(000 . "WIPEOUT") '(100 . "AcDbEntity") '(100 . "AcDbWipeout") (cons 10 (trans p 1 0)) (cons 11 (trans (list m 0.0) 1 0)) (cons 12 (trans (list 0.0 m) 1 0)) '(280 . 1) '(070 . 7) '(071 . 2) ) (mapcar (function (lambda ( x ) (cons 14 (mapcar '(lambda ( a b c ) (/ (- a b) c)) x c (list m (- m)))) ) ) l ) ) ))(vl-load-com) (princ)
PS: FWIW, the wipeout code is actually mine from this thread. |