Skip to content

Instantly share code, notes, and snippets.

@abynim
Last active April 30, 2024 09:58
Show Gist options
  • Select an option

  • Save abynim/04f88d5e4fe47118bfe3 to your computer and use it in GitHub Desktop.

Select an option

Save abynim/04f88d5e4fe47118bfe3 to your computer and use it in GitHub Desktop.

Revisions

  1. abynim revised this gist Jul 13, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions Sketch Plugin Snippet - Select layers of Type.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,16 @@
    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]
  2. abynim renamed this gist Jul 13, 2015. 1 changed file with 10 additions and 9 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,22 @@
    var selectLayers = function(ofType, inContainer) {
    var doc = context.document,
    scope = (typeof inContainer !== 'undefined') ? [inContainer children] : [[doc currentPage] children],
    predicate = NSPredicate.predicateWithFormat("(className == %@)", ofType),
    var doc = context.document

    var selectLayersOfType_inContainer = function(layerType, containerLayer) {
    var scope = (typeof containerLayer !== 'undefined') ? [containerLayer children] : [[doc currentPage] children],
    predicate = NSPredicate.predicateWithFormat("(className == %@)", layerType),
    layers = [scope filteredArrayUsingPredicate:predicate];
    [[doc currentPage] deselectAllLayers]
    var loop = [layers objectEnumerator], layer;
    while (layer = [loop nextObject]) {
    [layer select:true byExpandingSelection:true]
    }
    log([layers count] + " " + ofType + "s selected")
    log([layers count] + " " + layerType + "s selected")
    }

    // Select all Text Layers in current page
    selectLayers("MSTextLayer")

    // Select all Artboards in current page
    //selectLayers("MSArtboardGroup")
    selectLayersOfType_inContainer("MSArtboardGroup")

    // Select all Text Layers in current page
    //selectLayersOfType_inContainer("MSTextLayer")

    // Types of layers that can be selected :
    // MSLayerGroup
  3. abynim created this gist Jul 7, 2015.
    25 changes: 25 additions & 0 deletions SketchPlugin - Select layers of Type
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    var selectLayers = function(ofType, inContainer) {
    var doc = context.document,
    scope = (typeof inContainer !== 'undefined') ? [inContainer children] : [[doc currentPage] children],
    predicate = NSPredicate.predicateWithFormat("(className == %@)", ofType),
    layers = [scope filteredArrayUsingPredicate:predicate];
    [[doc currentPage] deselectAllLayers]
    var loop = [layers objectEnumerator], layer;
    while (layer = [loop nextObject]) {
    [layer select:true byExpandingSelection:true]
    }
    log([layers count] + " " + ofType + "s selected")
    }

    // Select all Text Layers in current page
    selectLayers("MSTextLayer")

    // Select all Artboards in current page
    //selectLayers("MSArtboardGroup")

    // Types of layers that can be selected :
    // MSLayerGroup
    // MSShapeGroup
    // MSShapePathLayer
    // MSTextLayer
    // MSArtboardGroup