Message 1 of 10
Mtext Replace Color (from a True Color value to another value)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to change MTEXT and Attributes even within Blocks from a True Color Value 0,0,0 to another value, either another True Color Value or one of the AuotCAD standard 1 - 256 colors.
I found this routine below that allows the user to input a color to change and then input a color to change that color to, but I don't know how to modify it or if it is even possible to modify it for True Colors.
(vl-load-com)
(defun c:ChangeTextColor (/ ch_str_color attlst new i obj objn old ss)
(defun ch_str_color (str old new /)
(while (vl-string-search (strcat "\\C" (itoa old) ";") str)
(setq str (vl-string-subst
(strcat "\\C" (itoa new) ";")
(strcat "\\C" (itoa old) ";")
str
);vl
);setq str
);while
str
);;ch_str_color
(if (and (princ "\n Select Text, Mtext or Attribute object to change its color: ")
(setq ss (ssget "_:L"
'((-4 . "<OR")
(0 . "MTEXT,TEXT")
(-4 . "<AND")
(0 . "INSERT")
(66 . 1)
(-4 . "AND>")
(-4 . "OR>")
)
)
)
(setq old (getint "\n Enter the old color number: "))
(<= 0 old 256)
(setq new (getint "\n Enter the new color number: "))
(<= 0 new 256)
);and
(repeat (setq i (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i))))
objn (vla-get-objectname obj)
);setq
(cond ((= objn "AcDbMText")
(vla-put-textstring obj (ch_str_color (vla-get-textstring obj) old new))
)
((and (= objn "AcDbText")
(= (vla-get-color obj) old)
)
(vla-put-color obj new)
)
((= objn "AcDbBlockReference")
(setq attlst (vlax-invoke obj 'GetAttributes))
(foreach att attlst
(if (= (vla-get-mtextattribute att) :vlax-false)
(if (= (vla-get-color att) old)
(vla-put-color att new)
)
(vla-put-textstring att (ch_str_color (vla-get-textstring att) old new))
)
)
)
);; cond
);repeat
);if and
(princ)
)
Here's a link to the forum post where I pulled this lisp routine code from.