Skip to content

Instantly share code, notes, and snippets.

@getflourish
Created August 17, 2014 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getflourish/50f5f48812764abda4d2 to your computer and use it in GitHub Desktop.
Save getflourish/50f5f48812764abda4d2 to your computer and use it in GitHub Desktop.
// This plugin selects all layers that have the same fill color as the currently selected layer/s (command shift c)
// Can be used to combine colors that are visually very similar
#import 'inventory.js'
// Get an array of all selected colors
var count = 0;
var referenceColors = [];
var pages = [[doc pages]objectEnumerator];
var color;
var hexColor;
var layers;
for (var c = 0; c < selection.count(); c++) {
color = inventory.colors.getColorOf(selection[c]);
hexColor = [color hexValue]
referenceColors.push(hexColor);
}
// Loop through all pages, artboards, layers
while (page = [pages nextObject]) {
if (page.name != inventory.config.pageName){
layers = [[page children] objectEnumerator];
while (layer = [layers nextObject]) {
color = inventory.colors.getColorOf(layer);
if (color !== null) {
if (inventory.common.isIncluded(referenceColors, [color hexValue]) == 1) {
[layer select:true byExpandingSelection:true];
count++;
}
}
}
}
}
[doc showMessage: "Selected " + count + " layers."];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment