How to apply color properties

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
loulesko
Posts: 89
Joined: 2008-01-20 11:08:35
Location: California
Contact:

How to apply color properties

Post by loulesko » 2009-06-01 03:02:48

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

User avatar
phspaelti
Posts: 956
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to apply color properties

Post by phspaelti » 2009-06-01 05:10:51

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
philip

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: How to apply color properties

Post by Kino » 2009-06-01 07:28:19

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

User avatar
loulesko
Posts: 89
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Re: How to apply color properties

Post by loulesko » 2009-06-04 08:06:15

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

Post Reply