Find all CMYK Process Colors - Scripting - Adobe Illustrator Javascript

247 Views Asked by At

Good afternoon,

I have a block of code that is supposed to run through all of the active document's color swatches in the Swatches palette, and if it is a CMYK Process color, it will do stuff. The doing stuff I can figure out, but getting the process colors to be identified as "CMYK" or "Process" or both has become incredibly difficult for me.

Below is my entire script contents (is a .jsx file):


// Get the swatches
var swatches = app.activeDocument.swatches;

/*** DO NOT USE
var ColorModel = {CMYK: "CMYK", RGB: "RGB", LAB: "LAB", GRAY: "GRAY", SPOT: "SPOT", CMYK_PROCESS: "CMYK_PROCESS"};
***/

// Set the progress bar
var progressWindow = new Window("palette", "Script Progress", [150, 150, 600, 200]);
progressWindow.bar = progressWindow.add("progressbar", [20, 35, 420, 60], 0, swatches.length);
progressWindow.show();


// Function to round colors
function roundColorValues(color) {
    var col = color;
    col.cyan = Math.round(col.cyan);
    col.magenta = Math.round(col.magenta);
    col.yellow = Math.round(col.yellow);
    col.black = Math.round(col.black);

}

// Function to set colors
function setColorValues(color) {
    var col = color;

    if (col.cyan <= 3) {
        col.cyan = 0;
    }
    else if (col.magenta <= 3) {
        col.magenta = 0;
    }
    else if (col.yellow <= 3) {
        col.yellow = 0;
    }
    else if (col.black <= 3) {
        col.black = 0;
    }

}

// Loop through the swatches
for (i = 0; i < swatches.length; i++) {
    // Update the progress bar
    progressWindow.bar.value = i + 1;
    progressWindow.update();

    // Get the swatch
    var swatch = swatches[i];
    var colorModel = swatch.color.colorModel;

    // Check if swatch is CMYK
    if (colorModel == ColorModel.CMYK) {
        alert("CMYK Color Found");
        roundColorValues(swatch.color);
        setColorValues(swatch.color);
    }

}



// Close the progress bar
progressWindow.close();

// Show the alert
alert("Complete!");

The problem I am having is that all of my swatches will be Global Colors, more often than not.

I have used swatch.color.typename, swatch.color.space, swatch.color.colorType, and swatch.color.colorModel. All of the Global Process colors all come back as a color mode of Un-defined, using the swatch.color.typename will make them come back as SPOT COLOR.

Any help would be greatly appreciated, as I am just banging my head against the wall now.

0

There are 0 best solutions below