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
| const sketch = require("sketch") | |
| const util = require("util") | |
| const document = sketch.getSelectedDocument() | |
| const documentData = document.sketchObject.documentData() | |
| const selections = document.selectedLayers | |
| const selection = selections.layers[0] | |
| let layerName = 'Oval' | |
| let instanceOverrides = util.toArray(selection.sketchObject.overrideContainer().flattenedChildren()) |
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
| const sketch = require('sketch'); | |
| const document = sketch.getSelectedDocument(); | |
| const selection = document.selectedLayers; | |
| selection.forEach(layer => layer.sketchObject.fixGeometryWithOptions(0)); |
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
| const sketch = require('sketch'); | |
| const document = sketch.getSelectedDocument(); | |
| const page = document.selectedPage; | |
| var artboards = page.sketchObject.artboards(); | |
| var duplicates = []; | |
| artboards.forEach(function(artboard){ | |
| let match = artboards.find(a => a.name() == String(artboard.name())); |
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 sketch = require('sketch'); | |
| var document = sketch.getSelectedDocument(); | |
| var page = document.selectedPage; | |
| var count = 0; | |
| page.sketchObject.symbols().forEach(function(symbol){ | |
| var symbol = sketch.fromNative(symbol); | |
| if (symbol.overrides) { | |
| symbol.overrides.forEach(function(override){ |
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 artboards = context.document.valueForKeyPath("[email protected]"), | |
| artboardLoop = artboards.objectEnumerator(), | |
| artboard; | |
| while (artboard = artboardLoop.nextObject()) { | |
| artboard.exportOptions().setLayerOptions(2); | |
| } |
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
| function findStringInTextLayers(textToFind,exactMatch,currentPage) { | |
| var predicate = NSPredicate.predicateWithFormat("className == %@","MSTextLayer"), | |
| textLayers = NSMutableArray.array(); | |
| if (currentPage == 1) { | |
| var page = context.document.currentPage(); | |
| textLayers.addObjectsFromArray(page.children().filteredArrayUsingPredicate(predicate)); | |
| } else { | |
| var pages = context.document.pages(), |
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
| function sortLayerList(layers,output,reverse) { | |
| var layers = (reverse && reverse == 1) ? layers.reverseObjectEnumerator().allObjects() : layers, | |
| loop = layers.objectEnumerator(), | |
| layer; | |
| while (layer = loop.nextObject()) { | |
| var output = (output) ? output : layer.parentGroup(); | |
| layer.moveToLayer_beforeLayer(output,nil); | |
| } |
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
| log(context.document.documentData().objectID()); | |
| context.document.documentData().generateObjectID(); | |
| log(context.document.documentData().objectID()); |
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 layers = context.selection[0].children(), | |
| layersLoop = layers.objectEnumerator(), | |
| layer, | |
| minX = 0, | |
| maxX = 1000, | |
| minY = 0, | |
| maxY = 1000, | |
| bounds = NSMakeRect(minX,minY,maxX,maxY); | |
| // Deselect the container |
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
| MSLayerSelector.alloc().init().updateSelectionWithRect_page_extendSelection_options_(NSMakeRect(0,0,1000,1000),context.document.currentPage(),false,0); |
NewerOlder