Lee Mac 发表于 2022-7-5 19:22:19

 
这最初是出于设计——我认为,如果用户有意对数字内容或数字内容周围的文本部分应用颜色覆盖,他们不会希望这种颜色被改变。
 
 
现在,我在下面的更新代码中包含了一个单独的参数,您可以使用该参数更改应用于数字内容的ACI颜色(6=洋红色)。
 
除少数边缘情况外,应成功执行以下操作:

;; Colour Numerical MText-Lee Mac

(defun c:numcol ( / *error* col enx idx pat new rgx sel str )

   (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") (1 . "*#*"))))
       (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 'multilineactrue)
               (vlax-put-property rgx 'pattern    pat)
               (repeat (setq idx (sslength sel))
                   (setq enx (entget (ssname sel (setq idx (1- idx))))
                         str (assoc 1 enx)
                   )
                   (entmod (subst (cons 1 (vlax-invoke rgx 'replace (cdr str) new)) str enx))
               )
         )
         (princ "\nUnable to interface with RegExp object.")
       )
   )
   (*error* nil)
   (princ)
)
(vl-load-com) (princ)
显示与现有多行文字格式兼容的快速演示:
 

vernonlee 发表于 2022-7-5 19:25:23

 
嗨,李。感谢视频中的详细解释。
 
抱歉,但现在结果正好相反。当字母和数字颜色相同时,数字不能改变颜色。
 
只有当文本和数字的颜色不同时,它才会改变。
 
也许是沟通失误。
 
你最初的Lisp程序给出了我需要的结果(当数字/字母颜色相同时,数字会改变颜色),但我想选择其他颜色。
 
我只提到当数字/字母的颜色不同时数字不会改变的部分,因为我认为您创建了初始LISP以使数字能够改变,无论数字/字母的颜色是相同还是不同。
 
我的画实际上只由多行文字组成,字母和数字的颜色从一开始就相同。
 
希望你可以恢复到最初的Lisp程序,但可以像第二个Lisp程序一样选择颜色。

Lee Mac 发表于 2022-7-5 19:26:54

请上传一张显示所需结果的图纸,以及您认为程序返回错误结果的情况。

vernonlee 发表于 2022-7-5 19:29:29

 
嗨,李。
 
按要求附上。
 
 
仅更改数字LISP。图纸

Lee Mac 发表于 2022-7-5 19:32:33

请尝试以下操作:
;; 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 'multilineactrue)
               (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的建议)。

vernonlee 发表于 2022-7-5 19:37:11

 
嗨,李,
 
它现在工作得很好
 
谢谢你帮我解决这个问题。

Lee Mac 发表于 2022-7-5 19:41:24

太好了,不客气

vernonlee 发表于 2022-7-5 19:42:35

嗨,李,
 
我的数字前面有字母
 
例如,15A房间(客厅)
 
你能把Lisp程序调整成只包括数字旁边的字母吗
“15a房间(客厅)”>>>>“15a房间(客厅)”
 
谢谢

仅用LISP语言更改数字旁边的字母。图纸

Lee Mac 发表于 2022-7-5 19:45:36

此类例外情况需要手动修改;我不打算在自愿时间进一步发展这个项目。

vernonlee 发表于 2022-7-5 19:49:47

 
我理解李。
 
不过,谢谢你的帮助
页: 1 [2]
查看完整版本: 帮助:只改变颜色