Script to add a layer for each color fill code
i have designs with around 30 colours, with codes like these. #009245 and #ec3744. The colours i use change a lot so i have to individually select all and group each color.
I would like to know if there is already a script for grouping each color fill or adding each color fill to a different layer.
I tried Meta to make one but it did not work :
var doc = app.activeDocument;
var items = doc.pageItems;
var colors = {};
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item.fillColor) {
var color = item.fillColor.toString();
var hexMatch = color.match(/(\w{6})/g);
if (hexMatch) {
var hexCode = hexMatch[0].toLowerCase();
if (!colors[hexCode]) {
colors[hexCode] = [];
}
colors[hexCode].push(item);
}
}
}
for (var hexCode in colors) {
var layer = doc.layers.add();
layer.name = hexCode;
for (var j = 0; j < colors[hexCode].length; j++) {
colors[hexCode][j].moveToBeginning(layer);
}
}
Is there anything that is already made? I've searched but cant find anything that puts each color fill (in a closed shape or path) into a group or layer
