查找所有 CMYK 印刷色 - 脚本 - Adobe Illustrator Javascript

问题描述 投票:0回答:1

下午好,

我有一段代码应该遍历样本调色板中所有活动文档的颜色样本,如果它是 CMYK 印刷色,它会做一些事情。我可以做的事情,但是让印刷色被识别为“CMYK”或“Process”或两者对我来说变得非常困难。

下面是我的整个脚本内容(是.jsx文件):


// 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!");

我遇到的问题是我所有的色板通常都是全局颜色。

我用过

swatch.color.typename
swatch.color.space
swatch.color.colorType
swatch.color.colorModel
。所有的Global Process颜色都以
Un-defined
的颜色模式返回,使用
swatch.color.typename
将使它们以
SPOT COLOR
的形式返回。

任何帮助将不胜感激,因为我现在正用头撞墙。

javascript scripting adobe-illustrator cmyk
1个回答
0
投票

可能是关于这个的:

var swatches = app.activeDocument.swatches;

for (var i=0; i<swatches.length; i++) {
    var swatch = swatches[i];
    var color = swatch.color;

    if (color.typename == 'SpotColor') {
        color = color.spot.color;  // <--- get the color of the spot object
    }

    if (color.typename == 'CMYKColor') {
        roundColorValues(color);
    }
}


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);
}

// etc...
© www.soinside.com 2019 - 2024. All rights reserved.