Copy link to clipboard
Copied
Hello!
I'm in the print production industry and am trying to come up with a script that will search for colours used in the document / artboard (not the swatches in the swatch panel) and create a legend at the bottom of the artboard. I've found a number of examples for this but they all come up just short of what I need them to do. They either provide too much or too little information. I've spent countless hours trying to figure out how to reverse engineer them to work for my needs but no luck.
Essentially I want to somehow capture the functionality of the separation preview window when viewing a file in Overprint Preview mode. It has an option for "Show used spot colours only."
Since the sep preview panel also shows CMYK as well regardless of whether or not it is in the document I would also need to be able to check for this and if CMYK is present, add to the swatch legend and if not, leave them out.
Not sure how much is possible but is there also a way to check placed images for their colour breakdown? It's a rare occurrence but sometimes I get files with images that have spot channels embedded. Nice to have but not a deal breaker if I can't.
I've been able to create separate pieces of scripts that, if I could somehow combine them, might do everything I need but I'm hoping there might be a simpler, cleaner solution.
Here's what I've got...
Check document for raster items with CMYK
var doc = app.activeDocument;
var myRasterItems = doc.rasterItems;
var myRasterItemsCount = myRasterItems.length
for (var i = 0; i < myRasterItems.length; i++) {
if (myRasterItems[i].colorants == "Cyan,Magenta,Yellow,Black") {
alert("Image Contains CMYK");
}
}
Check document for vector items with CMYK. The idea here was to add CMYK "circles" to the legend if CMYK was present. However, this might not work so well if there is K but no CMY for example. I'm sure it could be taken further but this is where I am.
var doc = app.activeDocument;
var myItems = doc.pathItems;
for (var i = 0; i < myItems.length; i++) {
if (myItems[i].filled === true && myItems[i].fillColor instanceof CMYKColor) {
var fillCMYK = 1;
}
if (myItems[i].stroked === true && myItems[i].strokeColor instanceof CMYKColor) {
var strokeCMYK = 1;
}
}
if (fillCMYK || strokeCMYK === 1)
alert("CMYK in document")
else
alert("No CMYK in document")
This is the script in progress for creating the legend "circles." I'd like to credit the original creator but I've forgotten where I pulled this from.
var docRef = app.activeDocument;
var swatchBoxSize = parseFloat(19);
var swatchBoxTop = 132;
var swatchBoxLeft = 535.5;
var textJustify = Justification.CENTER;
for (i = docRef.swatches.length - 1; i >= 2; i--) {
var swatchRef = docRef.swatches[i];
var swatchRefName = docRef.swatches[i].name;
var swatchBox = docRef.pathItems.ellipse(swatchBoxTop, swatchBoxLeft, swatchBoxSize, swatchBoxSize);
swatchBox.fillColor = swatchRef.color;
swatchBox.stroked = false;
var swatchLabelX = swatchBoxLeft + swatchBoxSize / 2;
var swatchLabelY = swatchBoxTop - (swatchBox.height + 8);
var swatchLabel = docRef.textFrames.pointText([swatchLabelX, swatchLabelY]);
swatchLabel.contents = swatchRefName;
swatchLabel.textRange.justification = textJustify;
swatchLabel.textRange.characterAttributes.size = 6.2;
swatchLabel.textRange.characterAttributes.leading = swatchBoxSize / 3;
swatchLabel.textRange.characterAttributes.fillColor = docRef.swatches["[Registration]"].color;
swatchBoxLeft += (70); //distance from top to top when box is added
}
I've made a few modifications to the original and it works great except for the fact that it only looks for the swatches in the swatch panel. If it could be directed to used colours instead it would be perfect. Here's a screenshot. The three squares are vector art coloured with Pantone spots. The "SwatchPanel" spots should not be in the legend and there should be "circles" representing the CMYK in the purple rectangle.
It might also be nice if it could make a second row if there are more than a given number of swatches but beggars can't be choosers.
I hope all of this makes sense. Any help or a point in the right direction would be greatly appreciated! I'd love to stop banging my head against the wall. 😉
Copy link to clipboard
Copied
since your last script works well with swatches in the swatches panel, you can select your objects manually and create a new Swatch Group with all selected colors used. Then you can modify your script to go through all swatches in the Swatch Group you just created instead of processing all swatches in the document.
About adding a second row. Currently you started with a fixed (x, y) position and as you went through your swatches you increased the x position by 70 points. Now instead of going east forever, you need to check each pass against a maximum x position where when reach it you reset your x position to what you had when you started. At that point you also update your y position to start a new row below your existing circles.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now