ycpyxl 发表于 2025-4-22 14:38:41

文字替换代码,多行字替换不了,高手请帮忙看看


文字替换代码,多行字替换不了,高手请帮忙看看
CopyTextAToB 这个命令换成方便的命令就不行,比如换成AS

(defun c:CopyTextAToB (/ entA textA entB dataB done)
(if (setq entA (car (entsel "\n选择源文字A(将被复制的文字): "))))
    (if (wcmatch (cdr (assoc 0 (entget entA))) "*TEXT")
      (progn
      (setq textA (cdr (assoc 1 (entget entA)))
      (princ "\n选择目标文字B(将被替换的文字,右键结束): ")
      (while (not done)
          (if (setq entB (car (entsel)))
            (if (wcmatch (cdr (assoc 0 (entget entB))) "*TEXT")
            (progn
                (setq dataB (entget entB))
                (entmod (subst (cons 1 textA) (assoc 1 dataB) dataB))
                (entupd entB)
                (princ (strcat "\n已将文字B内容替换为: " textA))
            )
            (princ "\n选择的对象不是文字,请重新选择或右键结束。")
            )
            (setq done T) ; 用户按ESC或右键结束
          )
      )
      )
      (princ "\n选择的对象不是文字。")
    )
    (princ "\n未选择源文字。")
)
(princ)
)

xyp1964 发表于 2025-4-22 16:59:47

(defun c:tt ()
(if (and (setq s1 (car (entsel "\n选择源文字A(将被复制的文字): ")))
         (wcmatch (cdr (assoc 0 (entget s1))) "*TEXT")
         (setq tx (cdr (assoc 1 (entget s1))))
      )
    (while (and (setq s2 (car (entsel "\n选择目标文字B(将被替换的文字,右键结束): ")))
                (wcmatch (cdr (assoc 0 (entget s2))) "*TEXT")
         )
      (setq ent (entget s2))
      (entmod (subst (cons 1 tx) (assoc 1 ent) ent))
      (entupd s2)
    )
)
(princ)
)
页: [1]
查看完整版本: 文字替换代码,多行字替换不了,高手请帮忙看看