How to find spot color swatches with Lab color mode in Illustrator using scripts?
Copy link to clipboard
Copied
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();
}
Explore related tutorials & articles
Copy link to clipboard
Copied
I don't know why, but changing colorType to PROCESS throws a PARM error if the color mode (read as spotKind) is Lab. The only way I could proceed was by changing the color/color mode.
if (checkbox.value) {
// alert(checkbox.spotColor.spotKind);
try {
checkbox.spotColor.color = checkbox.spotColor.color;
checkbox.spotColor.colorType = ColorModel.PROCESS;
} catch (e) {
alert(e);
}
}
Copy link to clipboard
Copied
Hello @femkeblanco , thank you very much for your help.
The statement checkbox.spotColor.color = checkbox.spotColor.color; is very cleverly used, our original method was clumsy, as shown below:
if (checkbox.value) {
var cmykColor = new CMYKColor();
cmykColor.cyan = checkbox.spotColor.color.cyan;
cmykColor.magenta = checkbox.spotColor.color.magenta;
cmykColor.yellow = checkbox.spotColor.color.yellow;
cmykColor.black = checkbox.spotColor.color.black;
checkbox.spotColor.color = cmykColor;
checkbox.spotColor.colorType = ColorModel.PROCESS;
}
In addition, how can I use a script to find spot colors in Illustrator that are using the Lab color mode? Personally, I think the best approach is to handle the spot colors using the method mentioned earlier if they are in the Lab color mode, and directly convert other color modes that can be converted normally (e.g., RGB or HSB), while preserving their original color mode.

