Skip to main content
Participant
January 24, 2017
Answered

Script to insert used swatches

  • January 24, 2017
  • 1 reply
  • 1688 views

I print files from Illustrator to a plate imager. The artwork gets printed in color separation, so I put the filename in registration and the color names in their respective color so that the printing press operator knows what color belongs to each plate. I have already written a script to automatically insert the file name, but I'm having trouble coming up with one for the colors. I need the script to insert the name of only the swatches used in the file that is linked on the artboard, but also change the color of the text to its respective color. Please help!

This topic has been closed for replies.
Correct answer biddenback

Okay. So I've got all of my templates set up so the swatch list is blank when it is opened. That way, only the colors used in the placed files will show up in the swatches panel. Here's my code so far (don't laugh...I'm brand new at this!):

var docRef = app.activeDocument;

var myTextFrame = docRef.textFrames.add();

myTextFrame.contents = docRef.placedItems[0].file.name;
myTextFrame.position = [15,-1015];
charAttr = myTextFrame.textRange.characterAttributes;
charAttr.textFont = app.textFonts.getByName("Helvetica-Light");
charAttr.size = 12;
charAttr.fillColor = docRef.swatches[1].color;
var colorNames = docRef.textFrames.add();
var sL = docRef.swatches; 
var text = ''; 
for (var i = 0; i < sL.length; i++) { 
     if (sL.name != '[None]' && sL.name != '[Registration]') { 
          text += sL.name + ' '; 
     } 
}
colorNames.contents = text
colorNames.position = [15,-1000];
colAttr = colorNames.textRange.characterAttributes;
colAttr.textFont = app.textFonts.getByName("Helvetica-Light");
colAttr.size = 12;

All I need now is to the change the color of the swatch text to match their respective swatch names.

1 reply

Silly-V
Legend
January 24, 2017

So you have a document with placed files and you want to get the colors that are used inside those placed files?

Are they all spot colors?

Participant
January 25, 2017

Correct. Most of them are 100% Black, but if they have color then it is usually spot colors. We have a few CMYK files but those are pretty rare. I just need the color names to show up on the corresponding plate when I print it.