- (defun c:tt(/ AREA E ENT H HH I II LST P1 PA PA1 PA2 PB PB1 PB2 PC PC1 PC2 PCEN PD PD1 PD2 RECS TEXTH W WW WXH X Y)
- (vl-load-com)
- (setq texth 200)
- (if(setq recs (ssget '((0 . "LWPOLYLINE")(90 . 4))))
- (repeat (setq i (sslength recs))
- (setq ent (entget (ssname recs (setq i (1- i))))
- lst '()
- e (cdr(car ent))
- area (vlax-curve-getArea (Vlax-Ename->Vla-Object e))
- )
- (foreach n ent (if (= (car n) 10)(setq lst (cons (cdr n) lst))));遍历边界组合,将顶点存入lst内
- (setq pa (car lst) pb (cadr lst) pc (caddr lst) pd (cadddr lst));四个顶点坐标分别为pa,pb,pc,pd
- (setq pa1 (car pa) pa2 (cadr pa) pb1 (car pb) pb2 (cadr pb) pc1 (car pc) pc2 (cadr pc) pd1 (car pd) pd2 (cadr pd));顶点坐标值横竖坐标
- (setq pcen(mapcar '(lambda(x y)(*(+ x y) 0.5)) pa pc));取得中矩形点
- (setq p1(list (min pa1 pb1 pc1 pd1)(min pa2 pb2 pc2 pd2)));取得左下角点
- (if (and (equal (distance pa pc)(distance pb pd) 1e-8);判断是否为矩形
- (or(equal p1 pa 1e-8)
- (equal p1 pb 1e-8)
- (equal p1 pc 1e-8)
- (equal p1 pd 1e-8)
- )
- )
- (progn
- (setq w(- (max pa1 pb1 pc1 pd1)(min pa1 pb1 pc1 pd1));计算宽度
- h(- (max pa2 pb2 pc2 pd2)(min pa2 pb2 pc2 pd2)));计算高度
- (setq ww (rtos w 2 0))
- (setq hh (rtos h 2 0))
- (setq ii (rtos i 2 0))
- (setq wxh (strcat ww "*" hh "-" ii))
- (entmake (list '(0 . "TEXT")(cons 72 1)(cons 73 2) (cons 1 wxh) (cons 10 pcen)(cons 11 pcen) (cons 40 texth)))
- )
- (print "非矩形")
- )
- )
- )
- (princ)
- )
统计论坛有很多自己翻翻帖子。 |