Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Change all text color in text box

New Here ,
Sep 11, 2017 Sep 11, 2017

Hi guys and greetings from Norway!

I've got something that is almost working. I want to change the text color in a selected box from e.g. black to white.

Previously I have this script from another post at this site. However, it's a problem. It only changes the first paragraph. How do I make it cycle through all the text?

Pseudo-code could be either something that selects all text and then changes color of it, or something that counts the paragraphs and then cycle through them one by one. Any ideas on how to solve this?

Code:

var i, p, color; 

for (i=0; i<app.selection[0].paragraphs.length; i++) { 

    p = app.selection[0].lines

    color = makeColor("C=0 M=0 Y=0 K=0", ColorSpace.CMYK, ColorModel.process, [0, 0, 0, 0]); 

        p.fillColor = color;   

 

function makeColor(colorName, colorSpace, colorModel, colorValue) { 

    var doc = app.activeDocument; 

    var color = doc.colors.item(colorName); 

    if (!color.isValid) { 

        color = doc.colors.add({name: colorName, space: colorSpace, model: colorModel, colorValue: colorValue}); 

    } 

    return color; 

TOPICS
Scripting
5.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Sep 11, 2017 Sep 11, 2017

Hi,

It does not need to iterate.

If selection is text or textFrame use

var color = makeColor("C=0 M=0 Y=0 K=0", ColorSpace.CMYK, ColorModel.process, [0, 0, 0, 0]);

app.selection[0].texts.everyItem().fillColor = color;

//function makeColor (...) {...}

Jarek

Translate
Mentor ,
Sep 11, 2017 Sep 11, 2017

Hi,

It does not need to iterate.

If selection is text or textFrame use

var color = makeColor("C=0 M=0 Y=0 K=0", ColorSpace.CMYK, ColorModel.process, [0, 0, 0, 0]);

app.selection[0].texts.everyItem().fillColor = color;

//function makeColor (...) {...}

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 11, 2017 Sep 11, 2017
LATEST

Thank you very much, that worked!

I slimmed it down to NOT make a new swatch.

Black:

app.selection[0].texts.everyItem().fillColor = "Black";

Or for white:

app.selection[0].texts.everyItem().fillColor = "Paper";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines