本帖最后由 liuhe 于 2024-3-25 08:56 编辑
简单粗暴的方法是,复制这个图元,然后用自带命令分解(一定要是command的分解命令)成单行文字,就可以读取里面纯文本内容。高级一点的是,通过正则规则,格式化这些格式,输出纯文本。- ;;-------------------=={ UnFormat String }==------------------;;
- ;; ;;
- ;; Returns a string with all MText formatting codes removed. ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
- ;;------------------------------------------------------------;;
- ;; Arguments: ;;
- ;; str - String to Process ;;
- ;; mtx - MText Flag (T if string is for use in MText) ;;
- ;;------------------------------------------------------------;;
- ;; Returns: String with formatting codes removed ;;
- ;;------------------------------------------------------------;;
- (defun LM:UnFormat ( str mtx / _replace rx )
- (defun _replace ( new old str )
- (vlax-put-property rx 'pattern old)
- (vlax-invoke rx 'replace str new)
- )
- (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
- (progn
- (setq str
- (vl-catch-all-apply
- (function
- (lambda ( )
- (vlax-put-property rx 'global actrue)
- (vlax-put-property rx 'multiline actrue)
- (vlax-put-property rx 'ignorecase acfalse)
- (foreach pair
- '(
- ("\032" . "\\\\\\\")
- (" " . "\\\\P|\\n|\\t")
- ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
- ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
- ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}")
- ("$1" . "[\\\\]({)|{")
- )
- (setq str (_replace (car pair) (cdr pair) str))
- )
- (if mtx
- (_replace "\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str))
- (_replace "\" "\032" str)
- )
- )
- )
- )
- )
- (vlax-release-object rx)
- (if (null (vl-catch-all-error-p str))
- str
- )
- )
- )
- )
- (vl-load-com)
- _ (LM:UnFormat "{\\O\\C1;L\\C256;ee} {\\L\\C2;M\\C256;ac}" nil)
- "Lee Mac"
|