Hi Conrad,
Here's a function I put together a while back that you could easily use in a new lisp to do what you want.
;| Routine to find specified text and replace with new text. Works on Text,
Mtext, Attributes and Dimension text overrides.
WARNING: it will change all occurances of a pattern with the new text.
Such as: if "test" "contest" "testing" are all valid text entries in the
drawing, running this: (txtfind "test" "newtest") will change
the original text to "newtest" "connewtest" "newtesting", but for the
original intent of this routine that was not a problem. Modifications
may be made to force matching of whole word only.
by: Jeff Mishler Sept. 2003
|;
(defun txtfind (patt newpatt / count ss ent str txthgt match?)
(vl-load-com)
(vla-startundomark (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
(setq ss (ssget "X" '((0 . "TEXT,MTEXT,DIMENSION,INSERT"))))
(if (not ss)
(princ "\nNo Text entities found!")
(progn
(setq count -1)
(while (< (setq count (1+ count))(sslength ss))
(setq ent (entget (ssname ss count))
obj (vlax-ename->vla-object (cdr (car ent))))
(cond
((= (cdr (assoc 0 ent)) "TEXT")
(progn
(setq str (cdr (assoc 1 ent)))
(while (setq match? (vl-string-search patt str))
(setq str (vl-string-subst newpatt patt str))
(vla-put-textstring obj str)
);while
);progn
);first condition
((= (cdr (assoc 0 ent)) "DIMENSION")
(progn
(setq str (cdr (assoc 1 ent)))
(while (setq match? (vl-string-search patt str))
(setq str (vl-string-subst newpatt patt str))
(vla-put-textoverride obj str)
);while
);progn
);second condition
((= (cdr (assoc 0 ent)) "MTEXT")
(progn
(setq str (vla-get-textstring obj))
(while (setq match? (vl-string-search patt str))
(setq str (vl-string-subst newpatt patt str))
(vla-put-textstring obj str)
);while
);progn
);third condition
(t
(progn
(if (= (vla-get-hasattributes obj) :vlax-true)
(progn
(setq atts (vla-getattributes obj))
(foreach x (vlax-safearray->list (vlax-variant-value atts))
(setq str (vla-get-textstring x))
(while (setq match? (vl-string-search patt str))
(setq str (vl-string-subst newpatt patt str))
(vla-put-textstring x str)
);while
);for
);progn
);if
);progn
);last condition
);cond
);while
);progn
);if
(vla-endundomark (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
(princ)
);defun
Make sure this loads first in acaddoc.lsp, then add your lisp after it. Something like this:
(txtfind "badtext" "goodtext")