明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1838|回复: 5

怎样用lisp只选取"文字(包括多行文字)、尺寸、带属性的块"?

[复制链接]
发表于 2008-1-3 17:17 | 显示全部楼层 |阅读模式
怎样用lisp只选取"文字(包括多行文字)、尺寸、带属性的块"?
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2008-1-3 22:14 | 显示全部楼层
(SSGET '((-4 . "<OR") (0 . "*TEXT,DIMENSION") (-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>") (-4 . "OR>"))))
 楼主| 发表于 2008-1-4 07:03 | 显示全部楼层
本帖最后由 作者 于 2008-1-4 7:17:40 编辑

这是一个对只"文字(包括多行文字)、尺寸、带属性的块"加下划线的LISP,ZZXXQQ能不能帮我优化一下,提高CAD的运行速度:比如有些函数能不能用VLISP函数代替,,,因为图太大时,框选之后运行起来很慢!!
----->还有,想多补充一个的功能,就是如果有些地方已经加了下划线了,程序框选后,检测出已经加了下划线了就自动跳过,不再加下划线!
  1. (defun c:ga()
  2. (vl-load-com)
  3. (setvar "cmdecho" 0)
  4. (command "_.undo" "be")
  5. (setq oldclyer (getvar "clayer"))
  6. (setq chklay (tblsearch "layer" "RLP064_C240"))
  7. (setq ss (SSGET '((-4 . "<OR") (0 . "*TEXT,DIMENSION") (-4 . "<AND") (0 . "INSERT") (66 . 1) (-4 . "AND>") (-4 . "OR>"))))
  8. ; (setq ss (ssget '((-4 . "<not") (0 . "*line") (-4 . "not>"))))
  9. (setq len (sslength ss))
  10. (setq count 0)
  11. (setq count1 0)
  12. (repeat len
  13. (setq ent (ssname ss count))
  14. (setq endata (entget ent))
  15. (setq count (1+ count))
  16. (setq entlay (cdr (assoc 8 endata)))
  17. (setq entype (cdr (assoc 0 endata)))
  18. (cond
  19. ((= entype "DIMENSION")(dmdl))
  20. ((= entype "TEXT")(tadl))
  21. ((= entype "MTEXT")(tamdl))
  22. ((= entype "INSERT")(indl))
  23. (t nil)
  24. ))
  25. (command "._layer" "s" oldclyer "")
  26. (command "_.undo" "e")
  27. (prin1)
  28. )
  29. (defun tadl ()
  30. (command "ucs" "world")
  31. (setq pt10 (cdr (assoc 10 endata)))
  32. (setq txtang (cdr (assoc 50 endata)))
  33. (setq tbox (textbox endata))
  34. (setq xdat (caadr tbox))
  35. (setq txtht (cdr (assoc 40 endata)))
  36. (setq lspace (* txtht 0.25))
  37. (setq lpt (polar pt10 (- txtang (/ pi 2.0)) lspace))
  38. (setq lpt1 (polar lpt (+ txtang pi) (* txtht 0.25)))
  39. (setq lpt2 (polar lpt1 txtang (+ xdat (* txtht 0.5))))
  40. ; (setq orent (ssget "c" lpt1 lpt2))
  41. ; (if (= orent nil)
  42. ; (command "line" lpt1 lpt2 ""))
  43. (command "line" lpt1 lpt2 "")
  44. (setq linet (entlast))
  45. (if (/= entlay "RLP581")
  46. (progn
  47. (setq chklay (tblsearch "layer" "RLP064_C240"))
  48. (if (null chklay)
  49. (command "._layer" "m" "RLP064_C240" "color" "240"  "" "L" "continuous" "" "" "color"  "bylayer" "linetype" "s"  "bylayer"  "")
  50. (command "._layer" "t" "RLP064_C240" "on" "RLP064_C240" "u" "RLP064_C240" "" )
  51. )
  52. (command "._change" linet "" "p" "la" "RLP064_C240" "")
  53. )
  54. (progn
  55. (setq chklay (tblsearch "layer" "RLP064_C240FS"))
  56. (if (null chklay)
  57. (command "._layer" "m" "RLP064_C240FS" "color" "240"  "" "L" "continuous" "" "" "color"  "bylayer" "linetype" "s"  "bylayer"  "")
  58. (command "._layer" "t" "RLP064_C240FS" "on" "RLP064_C240FS" "u" "RLP064_C240FS" "" )
  59. )
  60. (command "._change" linet "" "p" "la" "RLP064_C240FS" "")
  61. )
  62. )
  63. (command "ucs" "p")
  64. )
  65. (defun dmdl()
  66. (command "._copy" ent "" "@" "@")
  67. (command "explode" ent)
  68. (setq ssdm (ssget "p"))
  69. (setq lendm (sslength ssdm))
  70. (setq cct 0)
  71. (repeat lendm
  72. (setq entdm (ssname ssdm cct))
  73. (setq endtdm (entget entdm))
  74. (setq dmtype (cdr (assoc 0 endtdm)))
  75. (if (= dmtype "MTEXT")
  76. (progn
  77. (command "explode" entdm)
  78. (setq entmt (entlast))
  79. (setq endata (entget entmt))
  80. (tadl)
  81. (vla-erase (vlax-ename->vla-object entmt))
  82. ; (entdel entmt);;在command命令作用中可能无效!!!!
  83. )
  84. (vla-erase (vlax-ename->vla-object entdm))
  85. ; (entdel entdm);;在command命令作用中可能无效!!!!
  86. )
  87. (setq cct (1+ cct))
  88. )
  89. )
  90. (defun indl()
  91. (setq ctstl (getvar "textstyle"))
  92. (setq cts (getvar "textsize"))
  93. (setq attdata (entget (entnext (cdr (assoc -1 endata)))))
  94. (setq txt (cdr (assoc 1 attdata)));clutch the attribute value for add text
  95. (setq txtstl (cdr (assoc 7 attdata)));clutch the style of attribute value
  96. (setq txtpt (cdr (assoc 10 attdata)));clutch the point for insert text
  97. (setq txth (cdr (assoc 40 attdata)));clutch the height of the attribute value
  98. (setq txts (assoc 41 attdata))
  99. (setq txtang (* (/ (cdr (assoc 50 attdata)) pi) 180));clutch the angle of the attribute value
  100. (setvar "textsize" txth)
  101. (command "text" txtpt "" txtang txt)
  102. ; (command "._text" "s" txtstl txtpt txth txtang txt)
  103. (setq atttxt (entlast))
  104. (setq endata (entget atttxt))
  105. (setq otxts (assoc 41 endata))
  106. (setq endata (subst txts otxts endata))
  107. (entmod endata)
  108. (if (/= ctstl txtstl)
  109. (setvar "textstyle" ctstl)
  110. )
  111. (if (/= cts  txth)
  112. (setvar "textsize" cts)
  113. )
  114. (tadl)
  115. (vla-erase (vlax-ename->vla-object atttxt))
  116. ; (entdel atttxt);;在command命令作用中可能无效!!!!
  117. (prin1)
  118. )
  119. (defun tamdl()
  120. (command "._copy" ent "" "@" "@")
  121. (command "explode" ent)
  122. (setq enttmt (entlast))
  123. (setq endtata (entget enttmt))
  124. (setq endata endtata )
  125. (tadl)
  126. )
  127. (prin1)
 楼主| 发表于 2008-1-6 06:52 | 显示全部楼层
ZZXXQQ有时间帮我看看吗?如果没有时间就算了!谢谢
发表于 2008-1-6 08:32 | 显示全部楼层

把程序复制了,呵^^^^我不会改,只是拿来学下

发表于 2008-1-6 11:58 | 显示全部楼层
  1. ;;;给文字下划线 carrot1983 2008-1-6
  2. (vl-load-com)
  3. (defun c:underLine (/ E ELST I O SS STR V0 V1 V2 VALUE)
  4.   ;;ss2Elst选择集->图元表
  5.   (defun ss2Elst (ss / elst)
  6.     (setq i 0)
  7.     (repeat (sslength ss)
  8.       (setq elst (cons (ssname ss i) elst)
  9.      i  (1+ i)
  10.       ) ;_ end setq
  11.     ) ;_ end repeat
  12.     (reverse elst)
  13.   ) ;_ end defun
  14.   (defun getValue (ename code)
  15.     (setq value (cdr (assoc code (entget ename))))
  16.   ) ;_ end defun
  17.   (defun replaceValue (e code val / data)
  18.     (setq data (entget e))
  19.     (setq data (subst (cons code val) (assoc code data) data))
  20.     (entmod data)
  21.   ) ;_ end defun
  22.   (setq ss (ssget '((-4 . "<or")
  23.       (0 . "*TEXT,DIMENSION,ATTDEF")
  24.       (-4 . "<and")
  25.       (0 . "INSERT")
  26.       (66 . 1)
  27.       (-4 . "and>")
  28.       (-4 . "or>")
  29.      )
  30.     ) ;_ end ssget
  31.   ) ;_ end setq
  32.   (setq elst (ss2Elst ss))
  33.   (foreach e elst
  34.     (setq v0 (getValue e 0)
  35.    v1 (getValue e 1)
  36.    v2 (getValue e 2)
  37.     ) ;_ end setq
  38.     (cond
  39.       ((and (wcmatch v0 "TEXT")
  40.      (/= "%%u" (strcase (substr v1 1 3) T))
  41.        ) ;_ end and
  42.        (replaceValue e 1 (strcat "%%u" v1))
  43.       )
  44.       ((and (wcmatch v0 "MTEXT") (not (VL-STRING-SEARCH "\\L" v1)))
  45.        (replaceValue e 1 (strcat "{\\L" v1 "}"))
  46.       )
  47.       ((and (wcmatch v0 "DIMENSION")
  48.      (not (VL-STRING-SEARCH "\\L" v1))
  49.        ) ;_ end and
  50.        (if (= v1 "")
  51.   (replaceValue e 1 (strcat "{\\L" "<>" "}"))
  52.   (replaceValue e 1 (strcat "{\\L" v1 "}"))
  53.        ) ;_ end if
  54.       )
  55.       ((and (wcmatch v0 "ATTDEF")
  56.      (/= "%%u" (strcase (substr v2 1 3) T))
  57.        ) ;_ end and
  58.        (replaceValue e 2 (strcat "%%u" v2))
  59.       )
  60.       ((wcmatch v0 "INSERT")
  61.        (progn
  62.   (setq o (vlax-ename->vla-object e))
  63.   (setq str (vla-get-TextString
  64.        (car (vlax-safearray->list
  65.        (vlax-variant-value (vla-GetAttributes o))
  66.      )
  67.        )
  68.      )
  69.   )
  70.   (if (/= "%%u" (strcase (substr str 1 3) T))
  71.     (vla-put-TextString
  72.       (car (vlax-safearray->list
  73.       (vlax-variant-value (vla-GetAttributes o))
  74.     )
  75.       )
  76.       (strcat "%%u" str)
  77.     )
  78.   ) ;_ end if
  79.        ) ;_ end progn
  80.       )
  81.     ) ;_ end cond
  82.   ) ;_ end foreach
  83.   (princ)
  84. ) ;_ end defun
  85. (defun c:tt ()
  86.   (c:underLine)
  87. ) ;_ end defun
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-10 16:02 , Processed in 0.143729 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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