Forked from abynim/Sketch Plugin Snippet - Select layers of Type.js
Created
February 4, 2018 10:53
-
-
Save monaye/1011d70090d5525eb08e07346d0f2761 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var doc = context.document | |
| var selectLayersOfType_inContainer = function(layerType, containerLayer) { | |
| // Filter layers using NSPredicate | |
| var scope = (typeof containerLayer !== 'undefined') ? [containerLayer children] : [[doc currentPage] children], | |
| predicate = NSPredicate.predicateWithFormat("(className == %@)", layerType), | |
| layers = [scope filteredArrayUsingPredicate:predicate]; | |
| // Deselect current selection | |
| [[doc currentPage] deselectAllLayers] | |
| // Loop through filtered layers and select them | |
| var loop = [layers objectEnumerator], layer; | |
| while (layer = [loop nextObject]) { | |
| [layer select:true byExpandingSelection:true] | |
| } | |
| log([layers count] + " " + layerType + "s selected") | |
| } | |
| // Select all Artboards in current page | |
| selectLayersOfType_inContainer("MSArtboardGroup") | |
| // Select all Text Layers in current page | |
| //selectLayersOfType_inContainer("MSTextLayer") | |
| // Types of layers that can be selected : | |
| // MSLayerGroup | |
| // MSShapeGroup | |
| // MSShapePathLayer | |
| // MSTextLayer | |
| // MSArtboardGroup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment