;;; (reptext <要找的文字> <替换成的文字>)
;;;应用举例:
;;;(SETQ char-A "DRAWING1" char-B "BDYCADCAD")
;;;(reptext char-A char-B)
;;;_______________________________________________________
(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) 能否象1楼一样 (command "zoom" "o" a1 "")因为现在不知道是改了那里.再好是提示要不要修改 同行,谢谢,很实用 错误: 输入的字符串有缺陷
是什么原因
页:
1
[2]