(defun c:rc(/ oldch newch sstxt ssl ct0 edata etext txtln subln ct1 ct2 schct DCL_ID newtext)
(setvar "cmdecho" 0)
(command "undo" "be")
(setq oldch "" newch "")
(if (> (setq DCL_ID (load_dialog "replace.dcl")) 0)
(progn
(if (new_dialog "replace" DCL_ID)
(progn
(mode_tile "oldword" 2)
(action_tile "oldword" "(setq oldch $value)")
(action_tile "newword" "(setq newch $value)")
(start_dialog)
)
(princ "\n 不能显示对话框")
)
(unload_dialog DCL_ID)
)
(princ "\n 不能打开对话框")
)
(if (and (/= "" oldch)(/= oldch newch)(setq sstxt (ssget '((-4 . "")))))
(progn
(setq ssl (sslength sstxt)
ct0 0
ct1 0
ct2 0
subln (strlen oldch)
)
(while (< ct0 ssl)
(setq edata (entget (ssname sstxt ct0))
etext (cdr (assoc 1 edata))
txtln (strlen etext)
schct 1
newtext ""
)
(while (<= schct txtln)
(setq newtext
(strcat newtext
(if (= (setq readch (substr etext schct subln)) oldch)
(setq ct1 (1+ ct1)
schct (+ schct subln)
newch newch
)
(progn
(setq schct (1+ schct))
(substr readch 1 1)
)
)
)
)
)
(if (/= etext newtext)
(progn
(entmod (subst (cons 1 newtext) (assoc 1 edata) edata))
(setq ct2 (1+ ct2))
)
)
(setq ct0 (1+ ct0))
)
(alert (strcat "所选文字中共有" (itoa ct2) "个文字含" (itoa ct1) "个 \"" oldch "\" 被替换为 \"" newch "\" ."))
)
)
(command "undo" "e")
(princ)
)