明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1865|回复: 1

[源码] lisp 替换字符串

[复制链接]
发表于 2014-1-6 21:03:51 | 显示全部楼层 |阅读模式
(defun c:fid (/ t1 s1 t2 txt1 txt2 n acc en ent new-ent)
  (while (null (setq en1 (car (entsel "\n请指定要查找的字符串:"))))
  )
  (setq t1 (y-dxf 1 en1))
  (setq s1 (ssget "x" (list (cons 0 "TEXT,MTEXT") (cons 1 t1))))
  (while (null (setq en2 (car (entsel "\n请输入要改为的字符串:"))))
  )
  (if (or (= (y-dxf 0 en2) "MTEXT") (= (y-dxf 0 en2) "TEXT"))
    (progn
      (setq t2 (y-dxf 1 en2))
      (setq txt2 (cons 1 t2))
      (setq n    (sslength s1)
        acc    0
      )
      (repeat n
    (setq en (ssname s1 acc))
    (setq ent (entget en))
    (setq txt1 (assoc 1 ent))
    (setq new-ent (subst txt2 txt1 ent))
    (entmod new-ent)
    (setq acc (1+ acc))
      )
    )
    (prompt "选择的不是文字,请重试!")
  )
  (princ)
)
(defun y-dxf (code en)
  (setq ent (entget en))
  (cdr (assoc code ent))
)

发表于 2014-10-9 17:42:48 | 显示全部楼层
辛苦了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-24 01:26 , Processed in 0.157801 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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