Last active
June 20, 2018 12:20
-
-
Save emalgholzad/b33f2ae848146f3cd7dd44811a66e230 to your computer and use it in GitHub Desktop.
Sketch plugin development cheat sheet
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
// NEW API | |
const sketch = require('sketch'); | |
const document = sketch.getSelectedDocument(); | |
const selection = document.selectedLayers; | |
const layerSelected = selection.layers[0]; | |
const style = layerSelected.style; | |
const borders = style.borders; | |
// OLD API | |
const doc = context.document; | |
const page = doc.currentPage(); | |
const selection = context.selection; | |
const style = selection[0].style(); | |
// sharedDoc | |
NSDocumentController.sharedDocumentController().currentDocument(); | |
// Example | |
var sketch = require('sketch') | |
var document = sketch.getSelectedDocument() | |
var selectedLayers = document.selectedLayers | |
var selectedCount = selectedLayers.length | |
if (selectedCount === 0) { | |
console.log('No layers are selected.') | |
} else { | |
console.log('Selected layers:'); | |
selectedLayers.forEach(function (layer, i) { | |
console.log((i + 1) + '. ' + layer.name) | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment