;;; Calculate area of closed polyline and place text in Sq.m in center of closed area
;;; Modified by Igal Aberbuh 2016
(defun C:at (/ acsp adoc ar axss hgt maxp minp obj p1 p2 pc ss txt)
(command "-style" "igal" "arial.ttf" "" "" "" "" "")
(vl-load-com)
(setq adoc (vla-get-activedocument
(vlax-get-acad-object)
)
)
(if (and
(= (getvar "tilemode") 0)
(= (getvar "cvport") 1)
)
(setq acsp (vla-get-paperspace adoc))
(setq acsp (vla-get-modelspace adoc))
)
(vla-startundomark (vla-get-activedocument
(vlax-get-acad-object)))
(initget 7)

(setvar 'textsize
(cond ((getdist (strcat "\nSpecify Area text height by two points on screen : ")))
((getvar 'textsize))
)
)

(prompt "\nSelect objects on screen to add area label")
(if (setq ss (ssget))
(progn

(setq axss (vla-get-activeselectionset adoc))
(vlax-for obj axss
(if (not
(vl-catch-all-error-p
(setq
ar (vl-catch-all-apply
(function (lambda()
(vlax-curve-getarea obj)))))))
(progn
(setq txt (strcat "Area = " (rtos ar 2 2)"m²"))
(vla-getboundingbox obj 'minp 'maxp)
(setq p1 (vlax-safearray->list minp)
p2 (vlax-safearray->list maxp)

pc (mapcar (function (lambda(a b)(/ (+ a b) 2))) p1 p2)

)
(vlax-invoke acsp 'Addtext txt pc (getvar 'textsize))
)
)
)
)
)
(vla-endundomark (vla-get-activedocument
(vlax-get-acad-object)))
(princ)
)

(princ)
(c:at)

Advertisements