明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 454|回复: 2

[提问] 求组文本拆分框选问题!!

[复制链接]
发表于 2018-5-2 22:34 | 显示全部楼层 |阅读模式
本帖最后由 tianbob 于 2018-5-2 22:37 编辑

感谢明经论坛,得一文字拆分,程序如下:
  1. (defun tiao ()
  2. (setq ang1 (atan y x))
  3. (setq d (distance pt pt1))
  4. (setq pt1 (polar pt (+ ang ang1) d))
  5. )
  6. (defun nextt (n /)
  7. (setq post (+ post n))
  8. (if (= hsc 0.8)
  9. (setq pt (polar pt angle_ (* distxt 0.9)))
  10. (setq pt (polar pt angle_ distxt))
  11. )
  12. )
  13. (defun C:exstr (/ styelay ent sel ellayt sty txt pt
  14. highscale angle_ angpost distxt stxt
  15. dxdy dxx dyy pt1p txt1 stxt1 ang1
  16. xy n
  17. )
  18. (setq stye (getvar "textstyle"))
  19. (setq lay (getvar "clayer"))
  20. (setvar "CMDECHO" 0)
  21. (setq ent (car (entsel "\n选择文字:")))
  22. (if (/= ent nil)
  23. (progn
  24. (setq sel (entget ent))
  25. (if (= "TEXT" (cdr (assoc 0 sel)))
  26. (progn
  27. (setq el (cdr (assoc -1 sel)))
  28. (command "erase" el "")
  29. (setq layt (cdr (assoc 8 sel)))
  30. (setq sty (cdr (assoc 7 sel)))
  31. (setq txt (cdr (assoc 1 sel)))
  32. (setq pt (cdr (assoc 10 sel)))
  33. (setq high (cdr (assoc 40 sel)))
  34. (setq scale (cdr (assoc 41 sel)))
  35. (setq angle_ (cdr (assoc 50 sel)))
  36. (setq ang (/ (* angle_ 180) pi))
  37. (setq post 1)

  38. (setq distxt (* high scale))
  39. (princ
  40. (strcat "\n文字间隔 : <" (rtos distxt 2 3) ">")
  41. )
  42. (setq distxt (getreal))
  43. (if (= distxt nil)
  44. (setq distxt (* high scale))
  45. )

  46. (command "style" sty "" "0" scale "0" "" "" "")
  47. (command "layer" "s" layt "")
  48. (setq p 1);
  49. (setq hsc 1);
  50. (setq txt1 (substr txt p 1)); 判断文字串中
  51. (repeat (strlen txt); 是否有汉字,
  52. (if(> (ascii txt1) 160)
  53. (setq hsc 0.8)
  54. );; 汉字ASCII大
  55. (setq p (1+ p));; 于160
  56. (setq txt1 (substr txt p 1)) ;
  57. );
  58. (setq stxt nil)
  59. (while (/= stxt "")
  60. (setq stxt (substr txt post 1))
  61. (if(<= (ascii stxt) 160)
  62. ;; 文字是西文
  63. (progn
  64. (setq dx (car pt))
  65. (setq dy (cadr pt))
  66. ;; 处理以%开始的扩展字符
  67. (cond ((= (ascii stxt) 37) ; 文字是: %
  68. (progn
  69. (setq stxt1 (substr txt (+ post 1) 1))
  70. (if (= (ascii stxt1) 37)
  71. ;;判断下一个文字是否也是: %
  72. (progn
  73. (setq stxt (substr txt post 5))
  74. (if (= hsc 0.8)
  75. (progn
  76. (setq x (* high 0.188))
  77. (setq dxx (+ dx x))
  78. (setq y (* high scale 0.1))
  79. (setq dyy (+ dy y))
  80. )
  81. (progn
  82. (setq dxx dx)
  83. (setq dyy dy)
  84. )
  85. )
  86. (setq pt1 (list dxx dyy))
  87. ;;(if (= hsc 0.8) (tiao)) ;如果有汉字, 调整pt1
  88. (command "text" pt1 (* high hsc) ang stxt)
  89. (nextt 5)
  90. )
  91. (progn
  92. (if (= hsc 0.8)
  93. (progn
  94. (setq x (* high 0.188))
  95. (setq dxx (+ dx x))
  96. )
  97. (setq dxx dx)
  98. )
  99. (if (= hsc 0.8)
  100. (progn
  101. (setq y (* high scale 0.1))
  102. (setq dyy (+ dy y))
  103. )
  104. (setq dyy dy)
  105. )
  106. (setq pt1 (list dxx dyy))
  107. ; (if (= hsc 0.8) (tiao)) ;如果有汉字, 调整pt1
  108. (command "text" pt1 (* high hsc) ang stxt)
  109. (nextt 1)
  110. )
  111. )
  112. )
  113. )
  114. ; 处理以%开始的扩展字符结束
  115. ; 处理其它的字母和数字
  116. (T
  117. (progn
  118. (if (= hsc 0.8)
  119. (progn
  120. (setq x (* high 0.188))
  121. (setq dxx (+ dx x))
  122. )
  123. (setq dxx dx)
  124. )
  125. (if (= hsc 0.8)
  126. (progn
  127. (setq y (* high scale 0.1))
  128. (setq dyy (+ dy y))
  129. )
  130. (setq dyy dy)
  131. )
  132. (setq pt1 (list dxx dyy))
  133. (if (= hsc 0.8)
  134. (tiao)
  135. );如果有汉字, 调整pt1
  136. (command "text" pt1 (* high hsc) ang stxt)
  137. (nextt 1)
  138. )
  139. )
  140. ; 处理其它的字母和数字结束
  141. )
  142. )
  143. ; 处理汉字
  144. (progn
  145. (setq stxt (substr txt post 2))
  146. (command "text" pt high ang stxt)
  147. (setq post (+ post 2))
  148. (setq pt (polar pt angle_ distxt))
  149. )
  150. ; 处理汉字结束
  151. )
  152. )
  153. (command "style" stye "" "" "" "" "" "" "")
  154. (command "layer" "s" lay "")
  155. (redraw)
  156. )
  157. (princ "\nObject is not a TEXT !")
  158. )
  159. )
  160. )
  161. (princ)
  162. )

但是只能对单独的一行文本进行拆分,不能框选多行文本,特请求大师帮忙优化和修改,感激不尽。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2018-5-3 11:08 | 显示全部楼层
路过,学习了,很受用。
发表于 2019-12-26 08:23 | 显示全部楼层
谢谢楼主分享!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-17 13:45 , Processed in 0.215353 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表