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

script random colours on letters

New Here ,
Mar 29, 2015 Mar 29, 2015

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
1.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

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];

  }

}());

Translate
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];

  }

}());

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

Awesome, thank you.

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

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

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

 

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