Setting specifed colours to overprint stroke, and converting to spots.
Hi guys, im playing around with an idea for some automation within our print studio. We have files that have several guides such as cutters and crease guide etc.
What I am trying to do with the script is to find the named swatches, make sure that they have the overprint stroke attribute applied and then make sure that they are spots, if not then convert them.
I have managed to get the funtionality working to update the overprint attribute, but sturggling with the conversion to spot colours. The code is not throwing up any errors, so i'm a bit stumped.
Any help would be much appreciated.
// Script to set overprint stroke for objects with specific stroke colours
function main() {
if (app.documents.length === 0) {
alert("Please open a document before running this script.");
return;
}
var doc = app.activeDocument;
var targetColorNames = ["Visual Area (Do not Print)", "Cutter Guide", "Crease Guide"];
var targetColors = [];
for (var i = 0; i < targetColorNames.length; i++) {
var color = doc.swatches.itemByName(targetColorNames[i]);
if (color.isValid) {
if (color.model === ColorModel.SPOT) {
targetColors.push(color);
} else {
targetColors.push(convertToSpotColor(color));
}
}
}
if (targetColors.length === 0) {
alert("None of the specified stroke colours were found in this document.");
return;
}
var allPageItems = doc.allPageItems;
for (var j = 0; j < allPageItems.length; j++) {
var item = allPageItems[j];
try {
if (
item.hasOwnProperty("strokeColor") &&
item.strokeColor !== null &&
item.hasOwnProperty("overprintStroke")
) {
for (var k = 0; k < targetColors.length; k++) {
if (item.strokeColor.name === targetColors[k].name) {
item.overprintStroke = true;
break;
}
}
}
} catch (e) {
$.writeln("Error processing item: " + e.message);
}
}
alert("Overprint stroke attribute has been applied to all matching objects.");
}
// Function to convert a process colour to a spot
function convertToSpotColor(color) {
try {
var doc = app.activeDocument;
if (color.model === ColorModel.PROCESS) {
var spotColor = doc.spots.add();
spotColor.name = color.name + " Spot";
spotColor.colorType = ColorModel.SPOT;
spotColor.color = color.color;
var spotSwatch = doc.swatches.add();
spotSwatch.name = spotColor.name;
spotSwatch.color = spotColor.color;
return spotSwatch;
} else {
return color;
}
} catch (e) {
$.writeln("Error converting colour to Spot: " + e.message);
return color;
}
}
main();