请高手帮我调试一下这lsp程序!
coolwzx1209
2009年10月21日 11:02:23
只看楼主

在网上找了一段文字替换的代码,我想改进下,就是文本自动替换,只要出现%%132就自动替换成},请问该如何实现?源代码:(defun reptext (char-A char-B / pc ss index ent typeA typeA-len char-Alen char-Blen n char-aa newsize ) (setq pc 0) (setq ss (ssget '((0 . "TEXT,MTEXT")))) ;选择文字

在网上找了一段文字替换的代码,我想改进下,就是文本自动替换,只要出现%%132就自动替换成},请问该如何实现?
源代码:
(defun reptext
(char-A char-B / pc ss
index ent typeA typeA-len char-Alen
char-Blen n char-aa newsize
)
(setq pc 0)
(setq ss (ssget '((0 . "TEXT,MTEXT")))) ;选择文字
(if ss
(progn
(setq index 0)
(repeat (sslength ss)
(setq ent (entget (ssname ss index)))
(setq index (+ 1 index))
(setq typeA (cdr (assoc 1 ent))) ;选择的文字内容
(setq typeA-len (strlen typeA)) ;选择的文字内容的长度
(setq char-Alen (strlen char-A)) ;取得要找的文字的长度
(setq char-Blen (strlen char-B)) ;取得替换文字的长度
(setq n 1)
(if (= char-A "")
(setq typeA-len 1)
)
(repeat typeA-len
(setq char-aa (substr typeA n char-Alen))
;查找选择的文字内容里是否有要被替换的文字
(if (= char-aa char-A)
(progn ;如果有
(setq typeA (vl-string-subst char-B char-A typeA))
(setq newsize (cons 1 typeA))
(setq ent (subst newsize (assoc 1 ent) ent))
(entmod ent)
(setq pc (1+ pc))
)
;;End progn
)
;;End if
(setq n (1+ n))
)
;;End repeat
)
;;End repeat
(princ (strcat "\n替换了" (rtos pc) "个."))
)
;;End progn
)
;;End if
)
;;;_______________________________________________________
(defun c:chtext (/ cm char-A char-B)
(setq cm (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "_.UNDO" "Group")
(setq char-A (getstring "\n请输入替换文字:"))
(setq char-B (getstring "\n请输入新的文字:"))
(reptext char-A char-B)
(command "_.UNDO" "End")
(setvar "cmdecho" cm)
(princ)
)
免费打赏
coolwzx1209
2009年10月21日 11:02:55
2楼
:time: :handshake
回复
zxc001
2009年11月03日 09:23:19
3楼
你还是下载我的 蓝天结构设计软件 那里面有替换的功能 很多种的 你的这个程序是子程序,是程序内部调用的程序,你加载能行,就是用不了,这样的才行 (defun c:
回复

相关推荐

APP内打开