Skip to main content
Taruz
New Participant
February 9, 2015
Question

Color letters in specific order via scripting? - Is it possible?

  • February 9, 2015
  • 3 replies
  • 2766 views

Hello everyone,

This is something I've done manually. The thing is, I'm going to do it with a quite long text and it would take an insane amount of time

doing it manually. How would I go about if I wanted to script this? Or is there an other way of doing this?

Help of any kind is greatly appreciated.

Thanks

This topic has been closed for replies.

3 replies

Brainiac
February 11, 2015

Taruz,

after your thread has deviated a bit, here something more on topic: Are you aware there are also ways to colorize text by means of transparency effects, without any scripting? Actually you can apply an arbitrary texture by combining the text frame with a picture that in your case could be just a rainbow... This works without turning the text into paths. Unfortunately I can't provide links, I only saw it mentioned on twitter. If you're interested it may help to repost these details in the regular forum.

Marc Autret
Brainiac
February 9, 2015

Hi Taruz,

This can be done using either nested styles or GREP styles.

Nested styles:

1) Highlight Drop Caps and Nested Styles in your paragraph style settings window.

2) Create a new nested style using the rule "Style1 through 1 character", where Style1 is a character style that loads the first color.

3) Do the same with Style2, Style3, etc.

4) Then, add a [Repeat] nested style over the last N styles, where N is the number of previously defined character styles (that is, the number of colors).

GREP styles:

Indiscripts :: Cyclic GREP Styles

@+

Marc

Community Expert
February 9, 2015

@Marc – I tested the GREP version (thank you for the patterns in your blog post) with 6 GREP Styles in one paragraph style.

Note: It's possible to spoil the pattern a bit, if the feature "Ligatures" is turned ON. (It is by default.)

See here:

Now the question is: Should the pattern start anew in every paragraph?
What to do, if we have table cells and the pattern should go on? Footnotes?

Then we need a more sophisticated approach by scripting this.

Uwe

Community Expert
February 10, 2015

@Uwe

This ligature issue is very enlightening, thanks! I never realized before that one cannot 'colorize' a character individually if that character belongs to a ligature. Yet it makes sense, since color is necessarily a glyph-level attribute.

Interestingly, you can note that the character 'h' (in the 'Th' ligature of your figure) has in fact the orange color applied, but this color is overridden by the red applied to the character 'T'. So, in a ligature, the first character wins.

@+

Marc


@Marc – yes, the Swatches Panel is showing an orange for the "h" glyph in the ligature "Th".

Since we are in the Scripting Forum here, we could ask for the fillColor.name of the individual character "h" in the ligature "Th" of my example.

Select the "h" and ask for:

var myFillColorName = app.selection[0].fillColor.name;

If we do, a red will be returned. That seems to be ok, but be cautious:

But that is misleading as well!

ALL the characters of that paragraph will return the same value: a red!

That's seem to be because of the first GREP Style in the rows of GREP Styles, that color all characters with a "red".

Select some more text, a bunch of different colored characters (5 in this case) and run the following snippet from the ESTK:

var myFillColorNamesArray = app.selection[0].texts[0].characters.everyItem().getElements();

for(var n=0;n<myFillColorNamesArray.length;n++){

    $.writeln(myFillColorNamesArray.fillColor.name);

    };

/*

RESULT IM MY CASE:

C=0 M=100 Y=100 K=0

C=0 M=100 Y=100 K=0

C=0 M=100 Y=100 K=0

C=0 M=100 Y=100 K=0

C=0 M=100 Y=100 K=0

*/

No different color names will be returned! Just the one name that is applied from the first GREP Style.

(InDesign CC-2014.1 on Mac OSX 10.7.5)

Now the question is: How can we make sure to get the "right" color names?
Let's probe this with textStyleRanges instead of individual characters:

app.selection[0].texts[0].textStyleRanges.length;

That will return one single textStyleRange ??!! How can that be…
Hm. No idea now how to test on for the rendered color on the page.

Uwe

Peter Spier
Community Expert
February 9, 2015

Moved to scripting...