Skip to main content
Aprking
Inspiring
August 15, 2023
Question

How to find spot color swatches with Lab color mode in Illustrator using scripts?

  • August 15, 2023
  • 1 reply
  • 597 views
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();
}

 

This topic has been closed for replies.

1 reply

femkeblanco
Legend
August 15, 2023

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);
    }
}
Aprking
AprkingAuthor
Inspiring
August 16, 2023

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.