Last active
August 29, 2015 14:05
-
-
Save getflourish/8ccf6a04f6255433c32f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Selects all text layers that have the same color as the reference layer | |
#import 'inventory.js' | |
// init | |
(function() { | |
var pageCount = 0, | |
color = null, | |
fill = null, | |
i = 0, | |
lastFoundOnPage = -1, | |
layer, | |
layerCount = 0, | |
layers, | |
page, | |
pages, | |
referenceColor = null, | |
referenceLayer = null, | |
selectedLayerCount = 0, | |
selectedLayers = [], | |
shapeLayerCount = 0; | |
// We need a reference layer | |
if (selection.count() === 1) { | |
// Remember the reference color | |
referenceLayer = selection[0]; | |
referenceColor = referenceLayer.style().fills().objectAtIndex(0).color(); | |
// Loop through pages | |
pages = doc.pages().objectEnumerator(); | |
while (page = pages.nextObject()) { | |
i++; | |
pageCount++; | |
// Loop through all children of the page | |
layers = page.children().objectEnumerator(); | |
while (layer = layers.nextObject()) { | |
layerCount++; | |
// Check if the layer is a shape group | |
if (layer.isKindOfClass(MSShapeGroup)) { | |
shapeLayerCount++; | |
try { | |
fill = layer.style().fills().objectAtIndex(0); | |
color = fill.color(); | |
if (fill != null) { | |
if (color.hexValue() === referenceColor.hexValue()) { | |
selectedLayerCount++; | |
layer.setIsSelected(true); | |
} | |
} | |
} catch (error) { | |
} | |
} | |
} | |
} | |
// Show how many layers have been selected | |
doc.showMessage(selectedLayerCount + " shape layers selected within " + | |
shapeLayerCount + " exisiting text layers within " + | |
layerCount + " layers on " + | |
pageCount + " pages."); | |
} else { | |
doc.showMessage("Please select a single reference text layer."); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment