- 积分
- 3727
- 明经币
- 个
- 注册时间
- 2007-10-19
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2019-11-16 23:21:44
|
显示全部楼层
本帖最后由 wudechao 于 2020-2-19 01:59 编辑
;文字表格秒居中(交叉线判断版),终结版本(经多次测试,比填充方式找中点约快215倍,2020.2.18修改 ffg-txtmpt函数,支持mtext和TCH_mtext,引进变量zg目的是加快处理表格速度,根据实际表格,适当修改一下这个dis的倍数)
(defun c:wzjz (/ *error* oos en ss n ptm disn diss dise disw date1 xx yy pt-dis dis zg)
(defun ffg-snearlin (pt ang scsz / scsz ss3 m en3 ent3 ty ent2 ptj lst ang1)
(vl-load-com)
(setq ss3 (ssget "f" (list pt (polar pt ang scsz)) '((0 . "LINE,LWPOLYLINE,POLYLINE") (8 . "~DEFPOINTS")))
lst nil
)
(if ss3
(progn
(setq m 0)
(while (setq en3 (ssname ss3 m))
(setq ent2 (entget en3)
ty (assoc 0 ent2)
)
(if (or
(= "LWPOLYLINE" (cdr ty))
(= "POLYLINE" (cdr ty))
)
(progn
(entmake (list '(0 . "LINE") (cons 10 pt) (cons 11 (polar pt ang scsz))))
(setq ent3 (entlast))
(setq ptj (vlax-invoke (vlax-ename->vla-object en3) 'intersectwith (vlax-ename->vla-object ent3) 0))
(entdel ent3)
)
(progn
(setq ptj (trans (vlax-curve-getclosestpointto en3 (trans pt 1 0) t) 0 1))
)
)
(setq ang1 (angle pt ptj))
(if (equal ang1 (* 2 pi) 0.087266)
(setq ang1 (* 2 pi))
)
(setq ang1 (rem ang1 (* 2 pi)))
(if (equal ang1 ang 0.087266)
(setq lst (cons (list (distance pt ptj) en3) lst))
)
(setq m (1+ m))
)
(apply
'min
(mapcar
'car
lst
)
)
)
)
)
(defun ffg-txtmpt (en2 / ent4 box ls pt4 ang4 pt-dis2 ty p1 p2 kuandu gaodu pt0)
(setq ent4 (entget en2))
(setq ty (cdr (assoc 0 (entget en2))))
(cond
((= ty "TCH_MTEXT")
(vla-getboundingbox (vlax-ename->vla-object en2) 'p1 'p2)
(setq p1 (safearray-value p1)
p2 (safearray-value p2)
)
(setq midpt (polar p1 (angle p1 p2) (* 0.5 (distance p1 p2))))
(setq pt-dis2 (list (trans midpt 0 1) (abs (distance p1 p2))))
)
((= ty "MTEXT")
(setq kuandu (cdr (assoc 42 (entget en2))))
(setq gaodu (cdr (assoc 43 (entget en2))))
(setq pt0 (cdr (assoc 10 (entget en2))))
(vla-getboundingbox (vlax-ename->vla-object en2) 'p1 'p2)
(setq p1 (safearray-value p1)
p2 (safearray-value p2)
)
(if (< (- (car pt0) (car p2)) 0)
(setq p2 (list (+ (car pt0) kuandu) (cadr pt0)))
(setq p2 (list (- (car pt0) kuandu) (cadr pt0)))
)
(if (> (- (cadr pt0) (cadr p1)) 0)
(setq p1 (list (car pt0) (- (cadr pt0) gaodu)))
(setq p1 (list (car pt0) (+ (cadr pt0) gaodu)))
)
(setq midpt (polar p1 (angle p1 p2) (* 0.5 (distance p1 p2))))
(setq pt-dis2 (list (trans midpt 0 1) (abs (distance p1 p2))))
)
((or
(= ty "TEXT")
(= ty "TCH_TEXT")
(= ty "ATTRIB")
)
(setq box (textbox ent4)
ang4 (cdr (assoc 50 ent4))
ls (mapcar
'(lambda (a b)
(* 0.5 (+ a b))
)
(car box)
(cadr box)
)
pt4 (cdr (assoc 10 ent4))
)
(setq pt-dis2 (list (trans (polar pt4 (+ ang4 (angle '(0 0) ls)) (distance '(0 0) ls)) 0 1) (abs (distance (car box)
(cadr box)
)
)
)
)
)
)
)
(vl-load-com)
(setvar "cmdecho" 0)
(defun *error* (msg)
(if oos
(setvar "osmode" oos)
)
(setvar "cmdecho" 1)
)
(command "undo" "begin")
(setq oos (getvar "osmode"))
(setvar "osmode" 0)
(setq ss (ssget '((0 . "TEXT,MTEXT,TCH_TEXT,TCH_MTEXT,ATTRIB")))
n 0
date1 (getvar "millisecs")
)
(while (setq en (ssname ss n))
(setq pt-dis (ffg-txtmpt en)
dis (cadr pt-dis);;文字对角线距离
zg (/ dis (cdr (assoc 40 (entget en))));;约等于长宽比
)
(setq ptm (trans (car pt-dis) 0 1)
disn (ffg-snearlin ptm (* 0.5 pi) dis)
diss (ffg-snearlin ptm (* 1.5 pi) dis)
)
(if (>= zg 3.0);长宽比很大的字
(progn
(setq dise (ffg-snearlin ptm 0.0 (* 1.5 dis));根据实际表格,适当修改一下这个dis的倍数
disw (ffg-snearlin ptm pi (* 1.5 dis));根据实际表格,适当修改一下这个dis的倍数
)
)
)
(if (and
(>= zg 1.6);长宽比中等的字
(< zg 3.0)
)
(progn
(setq dise (ffg-snearlin ptm 0.0 (* 3 dis));根据实际表格,适当修改一下这个dis的倍数
disw (ffg-snearlin ptm pi (* 3 dis));根据实际表格,适当修改一下这个dis的倍数
)
)
)
(if (< zg 1.6);长宽比小的字
(progn
(setq dise (ffg-snearlin ptm 0.0 (* 4 dis));根据实际表格,适当修改一下这个dis的倍数
disw (ffg-snearlin ptm pi (* 4 dis));根据实际表格,适当修改一下这个dis的倍数
)
)
)
(if (and
disn
diss
)
(setq yy (* 0.5 (- disn diss)))
(setq yy 0)
)
(if (and
dise
disw
)
(setq xx (* 0.5 (- dise disw)))
(setq xx 0)
)
(or
(= 0 xx yy)
(vla-move (vlax-ename->vla-object en) (vlax-3d-point ptm) (vlax-3d-point (list (+ (car ptm) xx) (+ (cadr ptm) yy))))
)
(setq n (1+ n))
)
(princ (strcat "\n耗时\"" (rtos (/ (- (getvar "millisecs") date1) 1000.000) 2 3) "\"秒"))
(command "undo" "end")
(setvar "osmode" oos)
(setvar "cmdecho" 1)
(princ)
) |
|