那就试试这个,应该可以用
;;;面积批量计算
(defun c:mjjs (/ ss j length1 m ent zbc i sum x y n2 cx cy x1 x2 p1 p3 p4 pt area)
(setvar "cmdecho" 0)
(vl-load-com)
(setq TextHeight (getdist "\n请输入文字高度:(默认1)"))
(if (= TextHeight nil) (setq TextHeight 1))
(while
(setq ss (ssget (list (cons 0 "CIRCLE,LWPOLYLINE,ELLIPSE")))
length1 (- (sslength ss) 1)
j 0
)
(while (>= length1 0)
(setq m (ssname ss length1)
ent (entget m)
zbc '()
i 1
sum 0
x 0
y 0
)
(foreach n1 ent
(if (= (nth 0 n1) 10)
(setq zbc (cons (cdr n1) zbc))
)
)
(foreach n2 zbc
(if (/= (rem i 2) 0)
(progn
(setq x1 (nth 0 n2)
y1 (nth 1 n2)
i (+ i 1)
)
(if (>= i 3)
(progn
(setq area (* (- (* x2 y1) (* x1 y2)) 0.500)
sum (+ sum area)
cx (* (- (* x2 y1) (* x1 y2)) (+ x2 x1))
cy (* (- (* x2 y1) (* x1 y2)) (+ y1 y2))
x (+ x cx)
y (+ y cy)
)
)
)
)
(progn
(setq x2 (nth 0 n2)
y2 (nth 1 n2)
area (* (- (* x1 y2) (* x2 y1)) 0.500)
sum (+ sum area)
cx (* (- (* x1 y2) (* x2 y1)) (+ x2 x1))
cy (* (- (* x1 y2) (* x2 y1)) (+ y1 y2))
i (+ i 1)
x (+ x cx)
y (+ y cy)
)
)
)
)
(if (= (rem i 2) 0)
(setq p1 (nth 0 zbc)
x2 (nth 0 p1)
y2 (nth 1 p1)
area (* (- (* x1 y2) (* x2 y1)) 0.5)
sum (+ sum area)
cx (* (- (* x1 y2) (* x2 y1)) (+ x2 x1))
cy (* (- (* x1 y2) (* x2 y1)) (+ y1 y2))
x (+ x cx)
y (+ y cy)
)
(setq p1 (nth 0 zbc)
x1 (nth 0 p1)
y1 (nth 1 p1)
area (* (- (* x2 y1) (* x1 y2)) 0.5)
sum (+ sum area)
cx (* (- (* x2 y1) (* x1 y2)) (+ x2 x1))
cy (* (- (* x2 y1) (* x1 y2)) (+ y1 y2))
x (+ x cx)
y (+ y cy)
)
)
(setq x (/ x (* sum 6))
y (/ y (* sum 6))
pt (list (- x 0.8) y)
p1 (list (+ x 0.8) y)
)
(setq sum (rtos (abs sum) 2 2)
length1 (- length1 1)
p3 (list x (+ y 0.3))
p4 (list x (- y 0.3))
j (+ j 1)