Copy link to clipboard
Copied
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;
}
1 Correct answer
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
...
Explore related tutorials & articles
Copy link to clipboard
Copied
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

