Skip to main content
Inspiring
September 7, 2025
Answered

Script to add a layer for each color fill code

  • September 7, 2025
  • 2 replies
  • 165 views

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

2 replies

CarlosCanto
Community Expert
Community Expert
September 7, 2025

can you elaborate? can you show before and after screenshots or share sample files?

 

ok, I see you found your answer

Inspiring
September 7, 2025

thanks , yes 🙂  thanks for checking .. People like you that help others are gentlemen to the extreme. (and gentlewoman) . Thanks

sams96826490AuthorCorrect answer
Inspiring
September 7, 2025