;~~~~~~~~~~~~~~~~~~替代文字内容(ct)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(defun c:ct()
(prompt "***改TEXT可用***此指令将图档内所有文字替换 如:将所有的~碳纤~文字 替换成~碳纤维~文字 ")
(setq oldtxt (getstring t "\n请输入原始文字内容:"))
(setq newtxt (getstring t "\n请输入更变后文字内容:"))
;(ssget "x" '((-4 . "<not")(-4 . "<or")(62 . 1)(62 . 5)(-4 . "or>")(-4 . "not>")))
;~~~~~~text型式的文字~~~~~~~~~~
(setq ss(ssget "X" '((0 . "text"))))
(setq oldnum (strlen oldtxt));旧字串长度
(setq newnum (strlen newtxt));新字串长度
(setq i 0)
(repeat (sslength ss)
(setq ssn (ssname ss i))
(setq ssdata (entget ssn))
(setq sstyp (cdr (assoc 0 ssdata)))
(setq p 1)
(setq ent (assoc 1 ssdata))
(setq entxt (cdr ent))
(setq ennum (strlen entxt))
(setq aa "")
(while (<= p ennum)
(setq kk (substr entxt p oldnum))
(if (= kk oldtxt)
(progn
(setq kk newtxt)
(setq p (- (+ p oldnum) 1))
)
(setq kk (substr entxt p 1))
);end if
(setq aa (strcat aa kk))
(setq p (1+ p))
);end while
(setq aa (cons 1 aa))
(setq ssdata (subst aa ent ssdata))
(entmod ssdata)
(setq i (1+ i))
);end repeat
;~~~~~~text型式的文字****到此结束~~~~~~~~~~
;~~~~~~Mtext型式的文字~~~~~~~~~~
(setq ssm(ssget "X" '((0 . "MTEXT"))))
(setq oldnum (strlen oldtxt))
(setq newnum (strlen newtxt))
(setq j 0)
(repeat (sslength ssm)
(setq ssn (ssname ssm j))
(setq ssdata (entget ssn))
(setq sstyp (cdr (assoc 0 ssdata)))
(setq p 1)
(setq ent (assoc 1 ssdata))
(setq entxt (cdr ent))
(setq ennum (strlen entxt))
(setq aa "")
(while (<= p ennum)
(setq kk (substr entxt p oldnum))
(if (= kk oldtxt)
(progn
(setq kk newtxt)
(setq p (- (+ p oldnum) 1))
)
(setq kk (substr entxt p 1))
)
(setq aa (strcat aa kk))
(setq p (1+ p))
)
(setq aa (cons 1 aa))
(setq ssdata (subst aa ent ssdata))
(entmod ssdata)
(setq j (1+ j))
);end repeat
)