这取决于你到底想要用什么 colored颜色 ,以及你使用的是哪种 colored颜色 .
例如,对于专色,可以是这样的:
var doc = app.activeDocument;
var sel = doc.selection;
// get all path items from the selection
var pathItems = [];
for (var i=0; i<sel.length; i++) get_all_pathItems(sel[i], pathItems);
// put all the colors into the object
var obj = {};
for (var i=0; i<pathItems.length; i++) {
var item = pathItems[i];
if (item.filled) {
var color = item.fillColor;
if (color instanceof SpotColor) obj[color.spot.name] = color;
}
if (item.stroked) {
var color = item.strokeColor;
if (color instanceof SpotColor) obj[color.spot.name] = color;
}
}
// get a number of the colors from the object
var n = 0;
for (key in obj) n++;
// updated lines below:
// run some actions, perhaps you don't even need the number
for (key in obj) {
if (key == 'White') continue; // skip White color
// action 1
// action 2
// etc...
}
// ----------------------------------------------------------
// recursive function to fill the given array with all pathItems of given item
function get_all_pathItems(item, arr) {
try { if (item instanceof PathItem) arr.push(item) } catch(e) {}
try {
if (item instanceof GroupItem) {
var paths = item.pathItems;
for (var i=0; i<paths.length; i++) arr.push(paths[i]);
var groups = item.groupItems;
for (var i=0; i<groups.length; i++) get_all_pathItems(groups[i], arr);
}
} catch(e) {}
}
而且还有一个问题.在Illustrator中,一组项目可以有自己的 colored颜色 (填充和描边).据我所知,你不能用 playbook 来了解团队的 colored颜色 .脚本只能获取路径项的 colored颜色 ,而不能获取组.