http://bbs.mjtd.com/forum.php?mod=viewthread&tid=899&highlight=%CE%C4%D7%D6%B3%A4%B6%C8
(defun TextLength ( String / Tbox)
(setq Tbox (textbox (list (cons 1 String))))
(distance (car Tbox) (cadr Tbox))
)
示例: (TextLength "YourStringHere")
如果你想通过选定文字可使用以下语句
(TextLength (cdr (assoc 1 (entget (car (entsel "\n选择文字: "))))))
以下假定 ENT 为文字对象...
(setq ENTLIST (entget ENT))
(setq textlength (car (nth 1 (textbox ENTLIST))))
对于单行文字(非多行文字):
(defun GetTextLength (Ent / TxtBox TxtLgt)
(command "_UCS" "_OBJ" Ent)
(setq TxtBox (textbox (entget Ent))
TxtLgt (distance (car TxtBox) (list (caadr TxtBox) (cadar TxtBox)))
)
(command "_UCS" "_PRE")
TxtLgt
)
用法:
(if (and
(setq CurEnt (car (entsel "\nSelect Text: ")))
(= (cdr (assoc 0 (entget CurEnt))) "TEXT")
)
(setq TxtLgt (GetTextLength CurEnt))
)