请尝试以下操作:
- ;; Colour Numerical MText - Lee Mac
- (defun c:numcol ( / *error* col idx pat new obj rgx sel )
- (setq col 6 ;; ACI colour for numerical text
- pat "(?:\\{\\\\C\\d+\\;(-?\\d+(?:\\.\\d)?\\d*)\\})|(?-?\\d+(?:\\.\\d)?\\d*)([^0-9;|]{1}|$))"
- new (strcat "{\\C" (itoa col) ";$1$2}$3")
- )
- (defun *error* ( msg )
- (if (and (= 'vla-object (type rgx)) (not (vlax-object-released-p rgx)))
- (vlax-release-object rgx)
- )
- (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
- (princ (strcat "\nError: " msg))
- )
- (princ)
- )
-
- (if (setq sel (ssget "_:L" '((0 . "MTEXT") (-4 . "<OR") (1 . "*#*") (3 . "*#*") (-4 . "OR>"))))
- (if (setq rgx (vlax-get-or-create-object "vbscript.regexp"))
- (progn
- (vlax-put-property rgx 'global actrue)
- (vlax-put-property rgx 'ignorecase acfalse)
- (vlax-put-property rgx 'multiline actrue)
- (vlax-put-property rgx 'pattern pat)
- (repeat (setq idx (sslength sel))
- (vla-put-textstring
- (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
- (vlax-invoke rgx 'replace (vla-get-textstring obj) new)
- )
- )
- )
- (princ "\nUnable to interface with RegExp object.")
- )
- )
- (*error* nil)
- (princ)
- )
- (vl-load-com) (princ)
这个问题与文本的现有颜色无关,而是数字是字符串中的最后一个字符;我还更新了程序,以考虑跨多个DXF组的长文本内容的多行文字(感谢ronjonp的建议)。 |