;;; Filter close polylines by internal area range
;;; Author unknown

(defun c:fba ( / *Error* CNT ENT AREA MINAREA MAXAREA ss StartPoint EndPoint)
(vl-load-com)
(command "cmdecho" 0)
(defun *Error* (Msg)
(cond
((or (not Msg)
(member Msg '("console break"
"Function cancelled"
"quit / exit abort"
)
) ;close member
) ;close or
) ;close condition, no message to display
((princ (strcat "\nError: " Msg))) ;else display message
) ;close cond
(princ)
) ;close defun *Error*

(setq MINAREA (getdist "\nEnter minimum area value: "))
(setq MAXAREA (getdist "\nEnter maximum area value: "))

(if (ssget "I")
(setq SS (ssget "I" '((0 . "LWPOLYLINE"))))
(setq SS (ssget '((0 . "LWPOLYLINE"))))
) ;end if

(setq CNT 0)
(repeat (sslength SS)

(setq ENT (ssname SS CNT)
AREA (vla-get-area (vlax-ename->vla-object ENT))
StartPoint (vlax-curve-getStartPoint (vlax-ename->vla-object ENT))
EndPoint (vlax-curve-getEndPoint (vlax-ename->vla-object ENT))
) ;end setq

(if (or (and (= MAXAREA AREA) (equal StartPoint EndPoint))
(equal MINAREA AREA 0.00001)
(equal MAXAREA AREA 0.00001)
) ;end or
(setq CNT (1+ CNT))
(ssdel ENT SS)
) ;end if
) ;end repeat
(command "cmdecho" 1)
(if (> (sslength SS) 0)
(progn
(princ (strcat "Number of objects selected = "(itoa (sslength SS))))
(sssetfirst nil SS)
) ;progn
(princ "No objects met the criteria ") ;else
) ;end if
(*Error* nil)
(princ)
) ;end defun