admin 发表于 2024-3-2 20:17:01

改变多行文字的颜色为指定的颜色色号

改变多行文字的颜色为指定的颜色色号

(defun m1 (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" "(\\\\c|\\\\C)(.[^;]*);")
(setq s (vlax-invoke-method regex "Replace" s ""))
(vlax-release-object regex)
s
)
(defun c:tt (/ SS COR I E ENT MT)
(SETQ SS (SSGET '((0 . "MTEXT"))))
(IF (NOT SS)
    (VL-EXIT-WITH-VALUE 0)
)
(if (or (not cor11) (<= cor11 0) (> cor11 256))
    (setq cor11 1)
)
(SETQ COR NIL)
(WHILE (or (not cor) (<= cor 0) (> cor 256))
(IF
    (NOT (SETQ
         COR (GETINT (STRCAT "\n请输入颜色号<" (RTOS COR11 2 0) ">"))
         )
    )
   (SETQ COR COR11)
   (SETQ COR11 COR)
)
)
(SETQ I 0)
(REPEAT (SSLENGTH SS)
    (SETQ E   (SSNAME SS I)
          ENT (ENTGET E)
          MT(CDR (ASSOC 1 ENT))
          MT(M1 MT)
          i   (1+ I)
    )
    (setq ent (ENTMOD (SUBST (CONS 1 MT) (ASSOC 1 ENT) ENT))
          ent (ENTMOD (SUBST (CONS 62 COR) (ASSOC 62 ENT) ENT))
    )
)
(PRINC)
)

admin 发表于 2024-3-2 20:17:27


    public static void Test1()
    {
      var sf = OpFilter.Build(e => e.Dxf(0) == "MTEXT");
      PromptSelectionOptions pso = new PromptSelectionOptions() { MessageForAdding = "\n选择要修改颜色的多行文字", RejectObjectsOnLockedLayers = true };
      var r1 = Env.Editor.GetSelection(pso, sf);
      if (r1.Status != PromptStatus.OK)
            return;
      using var tr = new DBTrans();
      var mtList1 = r1.Value.GetEntities<MText>(OpenMode.ForWrite);
      if (!mtList1.Any())
            return;
      var r2 = Env.Editor.GetInteger("\n输入颜色号");
      if (r2.Status != PromptStatus.OK)
            return;
      var colorIndex = Math.Abs(r2.Value) % 257;
      foreach (var mt in mtList1)
      {
            mt.Contents = mt.Text;
            mt.ColorIndex = colorIndex;
      }
    }
页: [1]
查看完整版本: 改变多行文字的颜色为指定的颜色色号