@msarqui wrote:
....
Yes! I need to change the color of the word, not the whole phrase.
Exemple:
My original phrase is: "The banana cake"
If I chose the word banana in Step1 and color 2 in Step2, my phrase after the command will be: "The banana cake"
....
[Color 1, really, but let that pass....] In that particular instance, for Mtext as a vla-object in the variable 'mt':
(vla-put-TextString mt (vl-string-subst "{\\C2;banana}" "banana" (vla-get-TextString mt)))
In the generic case, if you've saved the color number [as a string] into a variable I'll call 'color' and the word/phrase into one called 'txt':
(vla-put-TextString mt (vl-string-subst (strcat "{\\C" color ";" txt "}") txt (vla-get-TextString mt)))
HOWEVER, be aware of the possible complications of other internal formatting. If, for example, the word banana also has a different font assigned, before you get into it for a color override, it will be starting with text content like this [in this example, the SCRIPTC font]:
"The {\\Fscriptc.shx|c0;banana} cake"
After giving the word "banana" color 2 manually, its resultant text content looks like this:
"The {\\Fscriptc.shx|c0;\\C2;banana} cake"
Note that the surrounding braces {} "wrap" both the Font and Color assignments -- there are not separate "wrappers" for each override -- so the simple string substitution above will cause trouble. Underlining is another possibility that would be encompassed within a single {} "wrapping" along with other override(s). And it gets even more complicated if any of those other overrides extends beyond the end of the word "banana" itself, in which case you could need an explicit change-back of the Color after the word, but without adding another } closure. Another complication is if the word already has a different Color override. Etc., etc. ....
Kent Cooper, AIA