Sg2.9
coloring individual letters
Recent RSS
coloring individual letters
From:  Brad
Date:  9. August 2007, 21:07

Hello, this may be an embarrassingly easy fix, but I'm a newbie. I'm trying to assign individual characters in a large text range a random selection out of an array of colors and can't get the thing to work.

Here's what I have:

var colorArray = new Array();
var sel = activeDocument.selectedItems;

colorArray[0] = new CMYKColor(0,15,41,15);
colorArray[1] = new CMYKColor(23.15,75.7,55.3,6.3);
colorArray[2] = new CMYKColor(0,11,20,20);
colorArray[3] = new CMYKColor(34.5,47.85,53.7,6.7);
colorArray[4] = new CMYKColor(8.25,20.8,37.65,0);

//assuming selected item is a text range
for(i=1; i<sel.length; i++){
sel.characters[i].setColor(colorArray[Math.round(Math.random()*(4-1))+1]);
}

I've made one work by appending a js script to the scripts menu in CS2 but it's very very slow (quite a few hours sometimes days slow). In case it helps though, here is the working script not used through scriptographer:

var colorArray = new Array();

colorArray[0] = new CMYKColor();
colorArray[0].cyan = 0;
colorArray[0].magenta = 15;
colorArray[0].yellow = 41;
colorArray[0].black = 15;

colorArray[1] = new CMYKColor();
colorArray[1].cyan = 23.15;
colorArray[1].magenta = 75.7;
colorArray[1].yellow = 55.3;
colorArray[1].black = 6.3;

colorArray[2] = new CMYKColor();
colorArray[2].cyan = 0;
colorArray[2].magenta = 11;
colorArray[2].yellow = 20;
colorArray[2].black = 20;

colorArray[3] = new CMYKColor();
colorArray[3].cyan = 34.5;
colorArray[3].magenta = 47.85;
colorArray[3].yellow = 53.7;
colorArray[3].black = 6.7;

colorArray[4] = new CMYKColor();
colorArray[4].cyan = 8.25;
colorArray[4].magenta = 20.8;
colorArray[4].yellow = 37.65;
colorArray[4].black = 0;

for(i=0; i<activeDocument.textFrames[0].contents.length; i++){
activeDocument.textFrames[0].textRange.characters[i].characterAttributes.fillColor = colorArray[Math.round(Math.random()*(4-1))+1];
}

I would be super grateful for any help towards a speedier solution
thank you kindly

  • Brad
Re: coloring individual letters
From:  Jürg Lehni
Date:  10. August 2007, 06:28

Hi Brad,

The range for color component values in Scriptographer is 0.0 to 1.0, so you should scale these values down to see results.

Crazy to hear how slow Adobe's scripting is... I have limited experience with it in InDesign, and it did not really shine with performance either...

Re: coloring individual letters
From:  Brad
Date:  10. August 2007, 18:29

to be fair to adobe the text range is really pretty big.

thanks for the help,
Brad

Re: coloring individual letters
From:  Brad
Date:  12. August 2007, 18:37

Another question(s):

can you use textrange.characters as an array or an arrayish object?

Do you have to call getCharacters first?

I've been trying different ways to select individual characters in the textRange to change their color, and so far the program doesn't seem to recognize index values, or .length or .contents. Any suggestions?

Here's what I have:

var colorArray = new Array();
var sel = activeDocument.selectedItems;

colorArray[0] = new CMYKColor(0.00,0.15,0.41,0.15);
colorArray[1] = new CMYKColor(0.23,0.75,0.55,0.60);
colorArray[2] = new CMYKColor(0.00,0.11,0.20,0.20);
colorArray[3] = new CMYKColor(0.34,0.48,0.54,0.70);
colorArray[4] = new CMYKColor(0.80,0.21,0.38,0.00);

//assuming selected item is a text range
//var SEL = sel.getCharacters();

for(i=0; i<sel.characters.length; i++){
sel.characters[i].setColor
(colorArray[Math.round(Math.random()*(4-1))+1]);
}

thanks again,
Brad

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Parallel Arrangement 07.04.12