香田里浪人 发表于 2013-11-25 07:37:16

;;;查找与替换
;;; (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)

ymcui 发表于 2013-11-25 11:38:49

能否象1楼一样   (command "zoom" "o" a1 "")因为现在不知道是改了那里.再好是提示要不要修改

xujinhua 发表于 2019-1-20 10:54:36

同行,谢谢,很实用

jiangmingxiu 发表于 2021-10-23 16:14:04

错误: 输入的字符串有缺陷
是什么原因
页: 1 [2]
查看完整版本: 快速查找CAD内的文字