(defun MText2Text (MTextString / RegExp s Pattern1 Pattern2 el) (setq RegExp (vlax-create-object "Vbscript.RegExp")) ;引用正则表达式控件 (vlax-put-property RegExp "IgnoreCase" 0) ;不忽略大小写 (vlax-put-property RegExp "Global" 1) ;匹配方式,全文字匹配 (setq s MTextString  attern1 (list (list "\\\\\\\\" 1 "\\") ;字符\\ (list "\\\\{" 2 "{") ;字符\{ (list "\\\\}" 3 "}") ;字符\} (list "\\\\P" 4 "\n") ;换行符\P )  attern2 (list "\\\\p(i|t)(.[^;]*);" ;段落缩进、制表符格式 "\\\\S(.[^;]*)(\\^|#|\\\\)(.[^;]*);" ;堆迭格式 "\\\\(F|f|C|H|T|Q|W|A)(.[^;]*);" ;字体、颜色、字高、字距、倾斜、字宽、对齐格式 "\\\\(L|l|O|o)" ;下划线、线格式 "\\\\~" ;不间断空格格式 "({|})" ;{} ;"\n" ;换行符格式(针对Shift+Enter格式) ) ) (foreach el Pattern1 (vlax-put-property RegExp "Pattern" (car el)) (setq s (vlax-invoke-method RegExp "Replace" s (chr (cadr el)))) ) (foreach el Pattern2 (vlax-put-property RegExp "Pattern" el) (setq s (vlax-invoke-method RegExp "Replace" s "")) ) (foreach el Pattern1 (vlax-put-property RegExp "Pattern" (strcat "\\x0" (itoa (cadr el))) ) (setq s (vlax-invoke-method RegExp "Replace" s (caddr el))) ) (vlax-release-object RegExp) s ) (defun c:tt () (if (setq ss (ssget '((0 . "MTEXT")))) (progn (setq i 0) (repeat (sslength ss) (setq ent (entget (ssname ss i)) i (1+ i) txt (cdr (assoc 1 ent)) txt (MText2Text txt) ent (subst (cons 1 txt) (assoc 1 ent) ent) ) (entmod ent) ) ) ) (princ) )
|