找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 708|回复: 0

[LISP程序]:replaces old text entity with new string

[复制链接]
发表于 2007-2-10 14:42:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
;replaces old text entity with new string
;REPACES TEXT WITH ONLY SPACES (I.E. " ") WITH THE TEXT "space"
;AND NULL TEXT WITH THE WORD "NULL TEXT"

  1. (defun c:CLEAN ( / spacetest ent space num count ans expl newen newlist newtext xx elist oldtxt oldlist)
  2. (sETVAR "CMDECHO" 0)
  3. ;********ERROR HANDLER**********************
  4. (defun *Error* (msg)
  5.   (if (/= msg "Function cancelled")
  6.     (princ (strcat "\nError: " msg))
  7.   )
  8. (terpri)
  9.                         
  10.   (setq *error* olderr)        
  11.   (princ)
  12. )
  13. ;***********************************************

  14. (setq badd nil)
  15. (SETQ SPACE (GETSTRING T "Press space bar for as many spaces to look for and fill in then enter: "))
  16. (setq num (rtos  (strlen space) 2 0 ))
  17. (setq newt "SPACE")
  18. (setq newtxt (cons 1 newt))
  19. (grtext -1 "Clean.lsp BY KWM '97")
  20. (setq oldtxt (CONS 1 space))
  21. (setq oldlist (list oldtxt))

  22. (setq lists (list (cons 0 "TEXT") oldtxt))

  23. (setq allents (ssget "X" lists))
  24. (IF ALLENTS
  25. (PROGN
  26. (setq n 0)
  27. (setq spacetest 1)
  28. (setq total (sslength allents))
  29. (setq ent (ssname allents 0))
  30. (while ent
  31. (setq elist (entget ent))
  32. (setq elist (subst newtxt oldtxt elist))
  33. (entmod elist)
  34. (setq n (1+ n))
  35. (setq ent (ssname allents n))
  36. (princ (strcat "\rFound and changed " (rtos n 2 0) " of " (rtos total 2 0) " space entities."))
  37. );END WHILE
  38. );end progn
  39. (PRINC (strcat "No text found consisting of only " num " spaces."))
  40. );end if
  41. (princ "\n")
  42. (renul)
  43. (if (or badd spacetest)
  44.       (progn
  45.         (initget 1 "Y YES N NO")
  46.         (setq ans (getkword "\rNull text and/or space text was found in your drawing! Do you wish to globally remove these enitites?: "))
  47.            (if (wcmatch (strcase ans) "Y*")
  48.                  (progn
  49.                    (if spacetest (res))
  50.                    (princ "\n")
  51.                     (if badd (ren))
  52.                 );end progn
  53.            );end if
  54.        );end progn
  55. );end if
  56. (setq badd nil)
  57. (princ)
  58. );end funct
  59. ;*X*X*X*X*X*X*X*X*X**X*X*X*X*X*X*X*X*X*X*X*X**X*X*X*X*X*X*X*X*X*X*X*X*X*X**X*X*X*X*X*X*X*X*X
  60. (DEFUN RES ( / ent elist )
  61. (setq n 0)
  62. (setq lists (list (cons 0 "TEXT") (cons 1 "SPACE") ))
  63. (setq allents (ssget "X" lists))
  64. (setq ent (ssname allents 0))
  65. (while ent
  66. (entdel ent)
  67. (setq n (1+ n))
  68. (setq ent (ssname allents n))
  69. (princ (strcat "\rErased " (rtos n 2 0) " of " (rtos total 2 0) " spaced out entities.                        "))
  70. (princ)
  71. )
  72. )
  73. ;*x*x*x*xx*x*x*x*x*xx**x*x*x*x*x*x*x*x*x*x*x*x**x*x*x*x*x*x*x**x*x*x*x*x*x*x*x**x*x*x*x*x*x*x
  74. (defun renul ( / allents nxt elist niltx count)
  75. (setq allents (ssget "X" (list (cons 0 "TEXT"))))
  76.   (if allents
  77.       (progn
  78. (setq n 0 count 0 badd nil)
  79. (setq nxt (ssname allents n))
  80. (while nxt
  81. (Setq elist (entget nxt))
  82. (setq actxt (cdr(assoc 1 elist)))

  83. (if (= actxt "")
  84. (progn
  85. (setq badd 1)
  86. (setq count (1+ count))
  87. (setq niltx (cons 1 "null text"))
  88. (setq elist (subst niltx (assoc 1 elist) elist))
  89. (entmod elist)
  90. ));end if/progn

  91. (setq n (1+ n))
  92. (setq nxt (ssname allents n))
  93. );end while
  94.       (princ (strcat "\nFound " (rtos count 2 0) " null text entities!"))
  95.       (princ "\n   ")
  96.        );end progn
  97.       (princ "\nNo null text found.")
  98. );end if
  99. );end renul
  100. ;***************************************************************
  101. (defun ren ( / notextt zobo nope)
  102. (setvar "CMDECHO" 0)
  103. (setq notextt (cons 1 "null text"))
  104. (setq notextt (list notextt))
  105. (setq nothing (ssget "X" notextt))
  106. (setq zobo 0)
  107. (setq nope (ssname nothing zobo))
  108. (while nope
  109. (command "erase" nope "")
  110. (setq zobo (1+ zobo))
  111. (setq nope (ssname nothing zobo))
  112. )
  113. (setvar "CMDECHO" 1)
  114. (princ (strcat "\n" (rtos zobo 2 0)" null text entities erased") )
  115. (princ)
  116. );END
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-21 10:40 , Processed in 0.247351 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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