本帖最后由 逗亦斗霸 于 2024-12-17 15:24 编辑
- (defun c:tt (/ b box ent ent2 h i n name ty num pt pt10 str str1 str2)
- (while
- (and
- (setq pt (cadr (setq name (entsel "\n请选择文字: ") ) ) )
- (setq ent (entget (car name) ) )
- (if (= (cdr (assoc 0 ent) ) "TEXT")
- (progn
- (setq ty (ssget) )
- (command "JUSTIFYTEXT" "" ty "L")
- (setq str (cdr (assoc 1 ent) ) pt10 (cdr (assoc 10 ent) ) h (cdr (assoc 40 ent) ) ent2 (cdr ent) box (textbox ent2) n (fix (/ (- (car pt) (car pt10) ) (/ (- (car (cadr box) ) (car (car box) ) ) (strlen str) ) ) ) num 0 i 1)
- (repeat n (if (> (ascii (substr str i i) ) 160) (setq num (1+ num) ) ) (setq i (1+ i) ) )
- (if (= (rem num 2) 1) (setq n (1- n) ) )
- (setq str1 (substr str 1 n) str2 (substr str (1+ n) ) )
- (entmod (subst (cons 1 str1) (assoc 1 ent) ent ) )
- (setq ent2 (subst(cons 1 str2) (assoc 1 ent2) ent2 ) )
- (entmake (subst (cons 10 (list (car pt10) (- (cadr pt10) (* 1.4 h) ) ) ) (assoc 10 ent2) ent2) )
- )
- nil
- )
- )
- )
- )
原代码可以将对正方式为左对齐的单行文字打断成两行,我尝试加入修改对正方式的两段代码『(setq ty (entlast) ) 和 (command "JUSTIFYTEXT" ty "L")』后却不能正常使用了,请问问题出在哪里?另外,如果想将文字打断但位置不变的话怎么修改(打断的地方没有空格)?谢谢~
|