问题已解决,现放出源码.
在此感谢mccad的源码http://bbs.mjtd.com/thread-57445-1-1.html
- (DEFUN C:tt(/ N SS )
- (setq sstxt (ssget '((0 . "TEXT,MTEXT"))))
- (SETQ N 0)
- (WHILE (< N (SSLENGTH sstxt));;
-
- ;;去除MTEXT中字符串的格式
-
- (setq mtext (CDR(ASSOC 1 (ENTGET (SSNAME sstxt N)))))
- (setq txt (mtext2text mtext))
-
- ;;提取出厂编号,如"AQ-1-XX"
- (setq x1 (vl-string-search "编号" txt) )
- (setq x2 (vl-string-search "面积" txt) )
- (if (> x1 10)
-
- (progn
-
- (setq txtend (substr txt (+ x1 6) (- x2 (+ x1 13))))
- (print txtend)
- )
- )
-
- (SETQ N (1+ N))
- )
- )
- ;;; ==========================================
- ;;; 去除MTEXT中字符串的格式,转化为TEXT
- ;;; ==========================================
- (defun mtext2text(MTextString / regex s)
- (setq regex(vlax-create-object "Vbscript.RegExp")) ;引用正则表达式控件
- (vlax-put-property regex "IgnoreCase" 0) ;不忽略大小写
- (vlax-put-property regex "Global" 1) ;匹配方式,全文字匹配
- (setq s MTextString)
- ;替换\\字符
- (vlax-put-property regex "Pattern" "\\\\\\\\")
- (setq s(vlax-invoke-method regex "Replace" s (chr 1)))
- ;替换\{字符
- (vlax-put-property regex "Pattern" "\\\\{")
- (setq s(vlax-invoke-method regex "Replace" s (chr 2)))
- ;替换\}字符
- (vlax-put-property regex "Pattern" "\\\\}")
- (setq s(vlax-invoke-method regex "Replace" s (chr 3)))
- ;删除段落缩进格式
- (vlax-put-property regex "Pattern" "\\\\pi(.[^;]*);")
- (setq s(vlax-invoke-method regex "Replace" s ""))
- ;删除制表符格式
- (vlax-put-property regex "Pattern" "\\\\pt(.[^;]*);")
- (setq s(vlax-invoke-method regex "Replace" s ""))
- ;删除堆迭格式
- (vlax-put-property regex "Pattern" "\\\\S(.[^;]*)(\\^|#|\\\\)(.[^;]*);")
- (setq s(vlax-invoke-method regex "Replace" s ""))
- ;删除字体、颜色、字高、字距、倾斜、字宽、对齐格式
- (vlax-put-property regex "Pattern" "(\\\\F|\\\\f|\\\\C|\\\\H|\\\\\T|\\\\Q|\\\\W|\\\\A)(.[^;]*);")
- (setq s(vlax-invoke-method regex "Replace" s ""))
- ;删除下划线、删除线格式
- (vlax-put-property regex "Pattern" "(\\\\L|\\\\O|\\\\l|\\\\o)")
- (setq s(vlax-invoke-method regex "Replace" s ""))
- ;删除不间断空格格式
- (vlax-put-property regex "Pattern" "\\\\~")
- (setq s(vlax-invoke-method regex "Replace" s ""))
- ;删除换行符格式
- (vlax-put-property regex "Pattern" "\\\\P")
- (setq s(vlax-invoke-method regex "Replace" s ""))
- ;删除换行符格式(针对Shift+Enter格式)
- (vlax-put-property regex "Pattern" "\n")
- (setq s(vlax-invoke-method regex "Replace" s ""))
- ;删除{}
- (vlax-put-property regex "Pattern" "({|})")
- (setq s(vlax-invoke-method regex "Replace" s ""))
-
- ;替换回\\,\{,\}字符
- (vlax-put-property regex "Pattern" "\\x01")
- (setq s(vlax-invoke-method regex "Replace" s "\\"))
- (vlax-put-property regex "Pattern" "\\x02")
- (setq s(vlax-invoke-method regex "Replace" s "{"))
- (vlax-put-property regex "Pattern" "\\x03")
- (setq s(vlax-invoke-method regex "Replace" s "}"))
-
- (vlax-release-object regex)
- s
- )
|