Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

script to get the color name of compound path

Participant ,
Jul 15, 2024 Jul 15, 2024

Hello, below function don't get the color name if parameter is compound path Item, how can this be achieved?

function getColor(compoundItem) {
var colorName;
if (compoundItem.strokeColor instanceof SpotColor) { 
var stColorName = compoundItem.stroke.spot.name;
if(stColorName === "Diecut"){
colorName= "Diecut"; 
}
}
return colorName;
}

TOPICS
Scripting
118
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 16, 2024 Jul 16, 2024

Hi @rui huang, I've made a few tweaks to your function. To access the color(s) of a compoundPathItem, you must access it's first PathItem. For example:

function getStrokeColorName(compoundItem) {

    var colorName;

    if (
        !compoundItem.hasOwnProperty('pathItems')
        || 0 === compoundItem.pathItems.length
    )
        return;

    var firstPathItem = compoundItem.pathItems[0];

    if (firstPathItem.strokeColor instanceof SpotColor) {
        var stColorName = firstPathItem.stro
...
Translate
Adobe
Community Expert ,
Jul 16, 2024 Jul 16, 2024
LATEST

Hi @rui huang, I've made a few tweaks to your function. To access the color(s) of a compoundPathItem, you must access it's first PathItem. For example:

function getStrokeColorName(compoundItem) {

    var colorName;

    if (
        !compoundItem.hasOwnProperty('pathItems')
        || 0 === compoundItem.pathItems.length
    )
        return;

    var firstPathItem = compoundItem.pathItems[0];

    if (firstPathItem.strokeColor instanceof SpotColor) {
        var stColorName = firstPathItem.strokeColor.spot.name;
        if (stColorName === "Diecut") {
            return stColorName;
        }
    }

    return colorName;
};

Note that this function returns undefined if no spot stroke color is found. As written, there is no reason for the `colorName` variable, but I assume you will need it for your code.

- Mark 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines