Lt Dan's l 发表于 2022-7-6 11:10:08

创建一些文字,其中有旧的。
 
 

;;method by Alanj
;;modified by reid b.
(defun c:test (/ ss id ent a b)
(setq ss (ssget "_x" '((0 . "text,mtext")))
         id 0)
      (while (setq ent (ssname ss id))
      (if (wcmatch (strcase (cdr (setq a (assoc 1 (setq b (entget ent)))))) "*OLD*")
;;OLD must be uppercase
;;will only modify text with the word old in it
         (entmod (subst (cons 1 "NEW") a b))
      )
      (setq id (1+ id))
      )
(princ)
)

Lee Mac 发表于 2022-7-6 11:13:56

 

(defun c:test ( / old new )
;; © Lee Mac 2010

(setq old "Lee" new "Mac")

(
   (lambda ( s i / e )
   (if s
       (while (setq e (ssname s (setq i (1+ i))))
         (entupd
         (cdr
             (assoc -1
               (entmod
               (subst
                   (cons 1 new) (assoc 1 (entget e)) (entget e)
               )
               )
             )
         )
         )
       )
   )
   )
   (ssget "_X" (list (cons 0 "TEXT,MTEXT") (cons 1 old))) -1
)

(princ)
)
                  
 
^^容易得多

alanjt 发表于 2022-7-6 11:16:56

区分大小写。

alanjt 发表于 2022-7-6 11:19:55

(defun c:Test (/ new old ss)
(setq new "WoO"
       old "Hoo"
)

(if (setq ss (ssget "_X" '((0 . "MTEXT,TEXT"))))
   ((lambda (i / e s l)
      (while (setq e (ssname ss (setq i (1+ i))))
      (if (wcmatch (strcase (cdr (setq s (assoc 1 (setq l (entget e)))))) (strcase old))
          (entmod (subst (cons 1 new) s l))
      )
      )
    )
   -1
   )
)
(princ)
)

Lt Dan's l 发表于 2022-7-6 11:23:57

致李:,
似乎你的代码只会在编写时改变Lee。如果全部是大写或小写,文本将不会更改。这和使用
(ssget“_x”'((1。“Lee”))然后entmod?

Lee Mac 发表于 2022-7-6 11:29:47

 
是的,我承认我没有读完整的帖子,也不知道区分大小写是个问题。。。

Lt Dan's l 发表于 2022-7-6 11:31:48

别担心,我只是想学习
页: 1 [2]
查看完整版本: 自动选择文本