1. ;;说明:文字分割 V1.2!作者:fangmin723-2020.5.7
    2. (defun c:SF(/ ado btxt ent fontsty ftxt hig inpty locx n obj obtxtwid ppt pt spt tsyitm txt txtlong wid)
    3. (defun obtxtwid(txt pt hig wid fontsty n / ptlst)
    4. (setq ptlst (textbox (list '(0 . "TEXT") (cons 1 (substr txt 1 n)) (cons 10 pt) (cons 40 hig) (cons 41 wid) (cons 7 fontsty))))
    5. (abs (- (caadr ptlst) (caar ptlst)))
    6. )
    7. (setq ppt (getpoint "\n请选择放置点:"))
    8. (while (setq ent (entsel))
    9. (setq
    10. obj (Vlax-Ename->Vla-Object (Car ent))
    11. txt (Vla-Get-TextString obj)
    12. fontsty (Vla-Get-StyleName obj)
    13. pt (vlax-safearray->list (vlax-variant-value (Vla-Get-InsertionPoint obj)))
    14. ado (vla-get-ActiveDocument (vlax-get-acad-object))
    15. tsyitm (vla-Item (vla-get-TextStyles ado) fontsty)
    16. hig (vla-get-Height obj)
    17. wid (vla-get-Width tsyitm)
    18. spt (getpoint "\n请选择分割点:")
    19. n 1
    20. inpty (cadr (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint obj))))
    21. txtlong (abs (car (apply (function (lambda(x y) (mapcar '- y x))) (textbox (list '(0 . "TEXT") (cons 1 txt) (cons 10 pt) (cons 40 hig) (cons 41 wid) (cons 7 fontsty))))))
    22. )
    23. (cond
    24. ((= (vla-get-ObjectName obj) "AcDbText")
    25. (cond
    26. ((>= (vl-position (vla-get-Alignment obj) '(1 4 7 10 13)) 0)
    27. (setq locx (- (car pt) (* txtlong 0.5)))
    28. )
    29. ((>= (vl-position (vla-get-Alignment obj) '(2 8 11 14)) 0)
    30. (setq locx (- (car pt) txtlong))
    31. )
    32. (T (setq locx (car pt)))
    33. )
    34. )
    35. (T
    36. (cond
    37. ((>= (vl-position (vla-get-AttachmentPoint obj) '(2 5 8)) 0)
    38. (setq locx (- (car pt) (* txtlong 0.5)))
    39. )
    40. ((>= (vl-position (vla-get-AttachmentPoint obj) '(3 6 9)) 0)
    41. (setq locx (- (car pt) txtlong))
    42. )
    43. (T (setq locx (car pt)))
    44. )
    45. )
    46. )
    47. (while (< (+ locx (obtxtwid txt pt hig wid fontsty n)) (car spt)) (setq n (1+ n)))
    48. (if (> n 1)
    49. (progn
    50. (setq ftxt (substr txt 1 (- n 1)) btxt (substr txt n))
    51. (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (list (+ (car ppt) 1) inpty)) '(7 . "宋 宽0.7 高3") (cons 40 hig) '(71 . 4) '(41 . 28) (cons 1 ftxt)))
    52. (vla-put-TextString obj btxt)
    53. )
    54. (princ "\n此处没有分割文字的必要!!!")
    55. )
    56. )
    57. (princ)
    58. )

    (SF)文字指定位置分割.gif