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

script random colours on letters

New Here ,
Mar 29, 2015 Mar 29, 2015

Copy link to clipboard

Copied

Hey, I would like to select a text frame and use a script so that each letter gets randomly coloured with one of the swatches out of my panel.

I’ve seen there are scripts to colourise shapes, but it's important that it stays as a font. I don’t want to outline the font.

Does a script like this exist?

Thanks for any tips

TOPICS
Scripting

Views

936

Translate

Translate

Report

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

Advisor , Mar 30, 2015 Mar 30, 2015

here you go:

(function(){

  var tf=app.activeDocument.selection[0];

  var chars=tf.characters.everyItem().getElements();

  var col=app.activeDocument.swatches.length-1;

  for (var i=0; i<chars.length; i++){

  var rand=Math.floor((Math.random() * col) + 1);

  chars.fillColor=app.activeDocument.swatches[rand];

  }

}());

Votes

Translate

Translate
Advisor ,
Mar 30, 2015 Mar 30, 2015

Copy link to clipboard

Copied

here you go:

(function(){

  var tf=app.activeDocument.selection[0];

  var chars=tf.characters.everyItem().getElements();

  var col=app.activeDocument.swatches.length-1;

  for (var i=0; i<chars.length; i++){

  var rand=Math.floor((Math.random() * col) + 1);

  chars.fillColor=app.activeDocument.swatches[rand];

  }

}());

Votes

Translate

Translate

Report

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 ,
Mar 30, 2015 Mar 30, 2015

Copy link to clipboard

Copied

Awesome, thank you.

Votes

Translate

Translate

Report

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 ,
Mar 30, 2015 Mar 30, 2015

Copy link to clipboard

Copied

One more question. To avoid the black, white and non colour [which can't be deleted] - is it possible that the script only use colours out of a group?

Cheers

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 19, 2024 Apr 19, 2024

Copy link to clipboard

Copied

LATEST

Resurrecting a very old thread to say: 

 

chars is missing its iterator in the last line due to forum migration. It should begin chars[i] for anyone stumbling across it now. 

 

Votes

Translate

Translate

Report

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