- 积分
- 13480
- 明经币
- 个
- 注册时间
- 2019-3-22
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
;;多行文字样式清除
(defun C:mtx(/ ss i ent elist )
(if (setq ss(ssget '((0 . "TEXT,MTEXT"))))
(progn
(setq i 0)
(repeat (sslength ss)
(setq ent (ssname ss i))
(setq elist (entget ent))
(entmod
(subst
(cons 1
(mtext2text (cdr(assoc 1 elist)))
)
(assoc 1 elist)
elist
)
)
(setq i (1+ i))
)
)
)
)
;提取多行文字,去除无用格式符号--来自明经
(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
)
|
评分
-
查看全部评分
|