Page 1 of 1

How to apply color properties

Posted: 2009-06-01 03:02:48
by loulesko
Sorry to bother, but the Macro Reference is a little light on examples and I'm not a programmer. If I have a variable $value and I want to make all the text in that variable black, how to I apply the Color.black command.

Thank you
Lou

Re: How to apply color properties

Posted: 2009-06-01 05:10:51
by phspaelti
The Color.black command is a command which returns a constant. The result is a rgb value (0,0,0). You can use this in commands like the "Set Text Color" command. That command assigns the color value to the current selection.

In your case, I am guessing, the $value is not the current selection, but maybe a variable that you have created? Ideally one could set the attribute properties of such a variable directly, but the way I understand the manual, attribute properties are read only at the current time. So you will probably have to set the color at the time when you want to insert into your file.

philip

Re: How to apply color properties

Posted: 2009-06-01 07:28:19
by Kino
Well, attributes objects are read-only. As a workaround, you can convert $value (styled text) into RTF data, replace all colour definitions in the colour table with that of black, and convert the data into styled text again:

Code: Select all

$value = Encode RTF $value
$value = Cast to String $value
$value.replaceAll '(?<=;)\x5Cred\d+ \x5Cgreen\d+ \x5Cblue\d+(?= ;)', '\x5Cred0 \x5Cgreen0 \x5Cblue0', 'E-i'
$value = Decode RTF $value

Re: How to apply color properties

Posted: 2009-06-04 08:06:15
by loulesko
Thank you all for your replies. After some tooling around, my solution distilled down to some very simple steps which uses the :Format:Text Color command.

Lou