http://bbs.mjtd.com/forum.php?mod=viewthread&tid=899&highlight=%CE%C4%D7%D6%B3%A4%B6%C8

    1. (defun TextLength ( String / Tbox)
    2. (setq Tbox (textbox (list (cons 1 String))))
    3. (distance (car Tbox) (cadr Tbox))
    4. )
    5. 示例: (TextLength "YourStringHere")
    6. 如果你想通过选定文字可使用以下语句
    7. (TextLength (cdr (assoc 1 (entget (car (entsel "\n选择文字: "))))))
    8. 以下假定 ENT 为文字对象...
    9. (setq ENTLIST (entget ENT))
    10. (setq textlength (car (nth 1 (textbox ENTLIST))))
    11. 对于单行文字(非多行文字):
    12. (defun GetTextLength (Ent / TxtBox TxtLgt)
    13. (command "_UCS" "_OBJ" Ent)
    14. (setq TxtBox (textbox (entget Ent))
    15. TxtLgt (distance (car TxtBox) (list (caadr TxtBox) (cadar TxtBox)))
    16. )
    17. (command "_UCS" "_PRE")
    18. TxtLgt
    19. )
    20. 用法:
    21. (if (and
    22. (setq CurEnt (car (entsel "\nSelect Text: ")))
    23. (= (cdr (assoc 0 (entget CurEnt))) "TEXT")
    24. )
    25. (setq TxtLgt (GetTextLength CurEnt))
    26. )