Here is one I did for someone on the Adesk Ng. You can use/ingnore/change it all you want. Right now it only works in the current drawing, but that can easly be changed. It will look through text, mtext, tables, blocks, dimensions, and attribute definitions.
(defun c:ReplaceAllStrings (/ ActDoc DtextList MtextList)
(defun ReplaceAllStrings (Doc MtextReplcList DtextReplcList / tempObjType ColCnt RowCnt)
(defun ReplaceString (String ReplaceList MtextObj / strTest strReplc Pos IsFormat FormatList strTemp)
(foreach pair ReplaceList
(setq strTest (car pair))
(setq strReplc (cdr pair))
(setq Pos -1)
(while
(and
(< Pos (strlen String))
(setq Pos (vl-string-search strTest String (setq Pos (1+ Pos))))
)
(if (equal Pos 0)
(setq String
(strcat
strReplc
(if (<= (1+ (+ Pos (strlen strTest))) (strlen String))
(substr String (1+ (+ Pos (strlen strTest))))
""
)
)
)
(setq String
(strcat
(substr String 1 Pos)
strReplc
(if (<= (1+ (+ Pos (strlen strTest))) (strlen String))
(substr String (1+ (+ Pos (strlen strTest))))
""
)
)
)
)
(setq Pos (+ Pos (strlen strReplc)))
)
)
(if MtextObj
(progn
(setq Pos 1)
(setq FormatList '("A" "Q" "T" "S" "H" "F" "C"))
(setq IsFormat 0)
(while (<= Pos (strlen String))
(setq strTemp (substr String 1 1))
(cond
((= strTemp "\\")
(if (vl-position (substr String (1+ Pos) 1) FormatList)
(setq IsFormat (1+ IsFormat))
)
(setq Pos (1+ Pos))
)
((= strTemp ";")
(if (equal IsFormat 0)
(progn
(if (equal Pos 1)
(setq String
(strcat
"\\U+00B1"
(if (<= 2 (strlen String))
(substr String 2)
""
)
)
)
(setq String
(strcat
(substr String 1 (1- Pos))
"\\U+00B1"
(if (<= (1+ Pos) (strlen String))
(substr String (1+ Pos))
""
)
)
)
)
(setq Pos (+ Pos 7))
)
(progn
(setq IsFormat (1- IsFormat))
(setq Pos (1+ Pos))
)
)
)
(T (setq Pos (1+ Pos)))
)
)
)
)
String
)
;---------------------------------------------------------------------------------------
(setq BlkCol (vla-get-Blocks Doc))
(vlax-for Lo (vla-get-Layouts Doc)
(vlax-for Obj (vla-get-Block Lo)
(setq tempObjType (vla-get-ObjectName Obj))
(cond
((vl-position tempObjType '("AcDbText" "AcDbAttributeDefinition"))
(vla-put-TextString Obj (ReplaceString (vla-get-TextString Obj) DtextReplcList nil))
)
((= tempObjType "AcDbMText")
(vla-put-TextString Obj (ReplaceString (vla-get-TextString Obj) MtextReplcList T))
)
((wcmatch tempObjType "AcDb*Dimension")
(vlax-for tempObj (vla-Item BlkCol (cdr (assoc 2 (entget (vlax-vla-object->ename Obj)))))
(if (= (vla-get-ObjectName tempObj) "AcDbMText")
(vla-put-TextString tempObj (ReplaceString (vla-get-TextString tempObj) MtextReplcList T))
)
)
)
((= tempObjType "AcDbBlockReference")
(foreach Att (vlax-invoke Obj 'GetAttributes)
(vla-put-TextString Att (ReplaceString (vla-get-TextString Att) DtextReplcList nil))
)
(foreach Att (vlax-invoke Obj 'GetAttributes)
(vla-put-TextString Att (ReplaceString (vla-get-TextString Att) DtextReplcList nil))
)
)
((= tempObjType "AcDbTable")
(setq ColCnt 0)
(repeat (vla-get-Columns Obj)
(setq RowCnt 0)
(repeat (vla-get-Rows Obj)
(vla-SetText Obj (ReplaceString (vla-GetText Obj RowCnt ColCnt) DtextReplcList nil))
(setq RowCnt (1+ RowCnt))
)
(setq ColCnt (1+ ColCnt))
)
)
)
)
)
)
;------------------------------------------------------------------------
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq DtextList
(list
(cons "^" "\\U+00B0")
(cons ";" "\\U+00B1")
(cons "_" "\\U+06F8") ;; Doesn't like new string
(cons "|" "\\U+00BC")
(cons "{" "\\U+215C")
(cons "\\" "\\U+00BD")
(cons "}" "\\U+215D")
(cons "[" "\\U+00BE")
(cons "]" "\\U+215E")
(cons "~" "%%C")
(cons "<" "\\U+2104") ;; Doesn't like new string
(cons ">" "\\U+214A") ;; Doesn't like new string
)
)
(setq MtextList
(list
(cons "^" "\\U+00B0")
(cons "_" "\\U+06F8") ;; Doesn't like new string
(cons "|" "\\U+00BC")
(cons "\\{" "\\U+215C")
(cons "\\\\" "\\U+00BD")
(cons "\\}" "\\U+215D")
(cons "[" "\\U+00BE")
(cons "]" "\\U+215E")
(cons "~" "%%C")
(cons "<" "\\U+2104") ;; Doesn't like new string
(cons ">" "\\U+214A") ;; Doesn't like new string
)
)
(ReplaceAllStrings ActDoc MtextList DtextList)
(princ)
)
Edit: Updated code. I knew I had a better version, just coudn't find it before.