@Ashishs This is not perfect, but it attempts to strip out any color codes from the Text in the Mleader before replacing with the new color code. Try the updated code.
;|==============================================================
dimcol.lsp by Phil Kenewell - 11/25/2024
Description:
By request of a user on CADTutor.com
https://www.cadtutor.net/forum/topic/94150-looking-for-a-lsp-to-select-a-dimension-in-the-drawing-and-change-the-color-to-red-for-any-type-of-dimension-be-it-a-rotated-aligned-or-angular/
This program allows you to change the color of all selected Dimensions
and Leaders, QLeader, Mleaders.
Last Update:
11/27/2024 = Added variable cl and (acad_colordlg) to select the
color at start instead of hardcoding.
===============================================================|;
(defun c:dimcol (/ cl co e e2 i l l2 n o ss tx)
(vl-load-com)
;-----------------------------
;; Change this variable to Change the color. ACI color number integer:
(setq cl 5); 1=RED, 2=YELLOW, 3=GREEN, 4=CYAN, 5=BLUE, 6=MAGENTA etc...
;(setq cl (acad_colordlg cl)); Alternately select color at beginning.
;---------------------------------------------------------------------
(command "._undo" "_Begin")
(if (setq ss (ssget '((0 . "DIMENSION,*LEADER"))))
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
l (entget e)
)
(cond
((wcmatch (cdr (assoc 0 l)) "DIMENSION,LEADER,QLEADER")
(command "._dimoverride" "_dimclre" cl "_dimclrd" cl "_dimclrt" cl "" e "")
(if (assoc 340 l)
(progn
(setq l2 (entget (setq e2 (cdr (assoc 340 l)))))
(if (assoc 62 l2)
(progn (entmod (subst (cons 62 cl) (assoc 62 l2) l2))(entupd e2))
(progn (entmod (append l2 (list (cons 62 cl))))(entupd e2))
)
)
)
)
((= (cdr (assoc 0 l)) "MULTILEADER")
(if (assoc 62 l)
(progn (entmod (subst (cons 62 cl) (assoc 62 l) l))(entupd e))
(progn (entmod (append l (list (cons 62 cl))))(entupd e))
)
(setq o (vlax-ename->vla-object e)
co (vla-get-leaderlinecolor o)
tx (vla-get-textstring o)
)
(vla-put-colorindex co cl)
(vla-put-leaderlinecolor o co)
(while (wcmatch tx "*\\C*;*")
(setq n 0)
(repeat 257
(setq tx (vl-string-subst "" (strcat "\\C" (itoa n) ";") tx)
n (1+ n)
)
)
)
(vla-put-textstring o
(strcat "\\C" (itoa cl) ";" tx)
)
)
)
)
)
(command "._Undo" "_End")
(princ)
)