Question
How to find spot color swatches with Lab color mode in Illustrator using scripts?
Hello friends!
How to use scripts in Illustrator to find spot color swatches with the color mode set as Lab in a document and convert them to global colors while retaining the Lab color mode?
The script below will encounter an error and stop the conversion when it encounters Lab color mode:
var doc = app.activeDocument;
var spotColors = doc.spots;
var dialog = new Window("dialog", "Convert Spot Colors to Global");
var panel = dialog.add("panel", undefined, "Select the spot colors to convert");
panel.orientation = "column";
panel.alignChildren = ["left","top"];
panel.spacing = 10;
panel.margins = 20;
for (var i = 0; i < spotColors.length; i++) {
var spotColor = spotColors[i];
if (spotColor.colorType === ColorModel.REGISTRATION || spotColor.colorType === ColorModel.PROCESS) {
continue;
}
var checkbox = panel.add("checkbox", undefined, spotColor.name);
checkbox.value = true;
checkbox.spotColor = spotColor;
}
if (panel.children.length === 0) {
alert("There are no spot colors in the current document!", "Reminder!");
} else {
var buttonsGroup = dialog.add("group");
buttonsGroup.alignment = "center";
buttonsGroup.add("button", undefined, "OK", { name: "ok" });
buttonsGroup.add("button", undefined, "Cancel", { name: "cancel" });
dialog.defaultElement = buttonsGroup.children[0];
buttonsGroup.ok.onClick = function () {
for (var i = 0; i < panel.children.length; i++) {
var checkbox = panel.children[i];
if (checkbox.value) {
checkbox.spotColor.colorType = ColorModel.PROCESS;
}
}
dialog.close();
};
buttonsGroup.cancel.onClick = function () {
dialog.close();
};
dialog.show();
}
