明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1831|回复: 3

[已解答] 根据文字内容和颜色删除选中文字的函数,求高手指点

[复制链接]
发表于 2014-7-21 14:26:39 | 显示全部楼层 |阅读模式
本帖最后由 ld_117 于 2014-7-21 15:52 编辑

第一次写lisp程序,函数功能很简单,试了好久功能终于实现了,但有些bug。执行完函数后删除了很多文字想要取消前一个操作,得一直undo才行,怎样才能一次undo就恢复要执行函数前的状态呢??
(defun C:zfpj (/ m all i t1 t2 t3 t4 t5 t6 t7 c1 r) (setq m:err *error* *error* *merr*)
(setq t1 "0 xAUy    ")
(setq t2 "     xAUy0")
(setq t3 "0 xAUy0")
(setq t4 "0 xADy    ")
(setq t5 "     xADy0")
(setq t6 "0 xADy0")
(setq t7 "     xAUy    ")
(setq t8 "     xADy    ")
(setq c1 253)
(setq i 0)
(prompt "选择图形")
(setq all (ssget '((0 . "TEXT,MTEXT"))))
(while (< i (sslength all))
(setq r 1)
(setq ss (ssname all i))
(setq i (1+ i))         
(setq alldata (entget ss))
(setq tcontent (cdr (assoc 1 alldata)))
(setq tcolor (cdr (assoc 62 alldata)))
(if (= tcolor c1) (setq r 2))
(if (= tcontent t1) (setq r 2))
(if (= tcontent t2) (setq r 2))
(if (= tcontent t3) (setq r 2))
(if (= tcontent t4) (setq r 2))
(if (= tcontent t5) (setq r 2))
(if (= tcontent t6) (setq r 2))
(if (= tcontent t7) (setq r 2))
(if (= tcontent t8) (setq r 2))
(if (= r 2) (command "erase" ss ""))
)
(command "UNDO" "E")
(princ)  )




 楼主| 发表于 2014-7-21 16:27:53 | 显示全部楼层
自己解决了。。。
发表于 2014-7-21 20:38:18 | 显示全部楼层
压缩一下
  1. (defun C:zfpj (/ m all i t1 t2 t3 t4 t5 t6 t7 c1 r)
  2. (setq m:err *error* *error* *merr*)
  3. (setq tlst '("0 xAUy    " "     xAUy0" "0 xAUy0" "0 xADy    " "     xADy0"
  4.               "0 xADy0" "     xAUy    " "     xADy    "))
  5. (setq c1 253)
  6. (prompt "选择图形")
  7. (if (setq all (ssget '((0 . "*TEXT")))) (progn
  8.   (repeat (setq i (sslength all))
  9.    (setq ss (ssname all (setq i (1- i))))        
  10.    (setq alldata (entget ss))
  11.    (setq tcontent (cdr(assoc 1 alldata)))
  12.    (setq tcolor (cdr(assoc 62 alldata)))
  13.    (if (or (= tccolor c1) (member tcontent tlst)) (entdel ss))
  14.   )
  15. ))
  16. (princ)
  17. )
 楼主| 发表于 2014-7-23 15:34:27 | 显示全部楼层
ZZXXQQ 发表于 2014-7-21 20:38
压缩一下

多谢,最近燃起了研究这个的热情,我会坚持的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-24 07:17 , Processed in 0.149462 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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