- 积分
- 3727
- 明经币
- 个
- 注册时间
- 2007-10-19
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2020-2-19 01:47:53
|
显示全部楼层
本帖最后由 wudechao 于 2020-2-19 02:00 编辑
;另外一种方法表格居中(填充判断版),缺点:表格必须封闭(前面那个是交叉线判断,速度快,且表格不需要封闭),这个速度比前面交叉线判断那个wzjz慢很多。优点:前面那个wzjz可能dis倍数问题,交叉线没有和表格相交,可能文字移动不了,这个可以,两个程序互补。建议:优先用前面那个,个别不行,才有这个。论坛某位大师的代码,我增加并修正了MTEXT,TCH_TEXT,TCH_MTEXT。
(defun c:wzjz2 (/ err)
(vl-load-com)
(setvar "cmdecho" 0)
(command ".undo" "be")
(defun algion (msg / ss lst i vlalst boxlst cor1 cor2 findboxpt newboxpt en1 en enlst date1 ty kuandu gaodu pt0)
(princ msg)
(setq ss (ssget '((0 . "TEXT,MTEXT,TCH_TEXT,TCH_MTEXT,ATTRIB"))))
(setq lst nil)
(setq i 0)
(setq date1 (getvar "millisecs"))
(repeat (sslength ss)
(setq lst (cons (ssname ss i) lst))
(setq i (1+ i))
)
(setq vlalst (mapcar
'vlax-ename->vla-object
lst
)
)
(setq boxlst (mapcar
'(lambda (x / cor1 cor2)
(vla-getboundingbox x 'cor1 'cor2)
(setq ty (vlax-get-property x 'objectname))
(if (= ty "AcDbMText")
(progn
(setq x (vlax-vla-object->ename x))
(setq kuandu (cdr (assoc 42 (entget x))))
(setq gaodu (cdr (assoc 43 (entget x))))
(setq pt0 (cdr (assoc 10 (entget x))))
(setq cor1 (safearray-value cor1)
cor2 (safearray-value cor2)
)
(if (< (- (car pt0) (car cor2)) 0)
(setq cor2 (list (+ (car pt0) kuandu) (cadr pt0)))
(setq cor2 (list (- (car pt0) kuandu) (cadr pt0)))
)
(if (> (- (cadr pt0) (cadr cor1)) 0)
(setq cor1 (list (car pt0) (- (cadr pt0) gaodu)))
(setq cor1 (list (car pt0) (+ (cadr pt0) gaodu)))
)
(setq x (vlax-ename->vla-object x))
(list cor1 cor2)
)
(list (vlax-safearray->list cor1) (vlax-safearray->list cor2))
)
)
vlalst
)
)
(setq findboxpt (mapcar
'(lambda (x)
(polar (car x) (angle (car x) (cadr x)) (/ (distance (car x) (cadr x)) 2.0))
)
boxlst
)
)
(setq newboxpt (mapcar
'(lambda (x)
(setq en1 (entlast))
(vl-cmdf "_boundary" "a" "i" "n" "n" "" x "")
(setq en (entlast))
(if (not (equal en1 en))
(progn
(setq enlst (entget en))
(setq lst (vl-remove-if-not '(lambda (y)
(= (car y) 10)
) enlst
)
)
(setq cor1 (vl-remove 10 (car lst))
cor2 (vl-remove 10 (nth 2 lst))
)
(entdel en)
(polar cor1 (angle cor1 cor2) (/ (distance cor1 cor2) 2.0))
)
)
)
findboxpt
)
)
(mapcar
'(lambda (x y y2)
(vla-move x (vlax-3d-point y) (vlax-3d-point y2))
)
vlalst
findboxpt
newboxpt
)
(princ (strcat "耗时\"" (rtos (/ (- (getvar "millisecs") date1) 1000.000) 2 3) "\"秒"))
)
(setq err (vl-catch-all-apply 'algion (list "\n请选择文字: ")))
(command ".undo" "e")
(setvar "cmdecho" 1)
(princ)
)
|
|