Skip to content

Instantly share code, notes, and snippets.

@janily
janily / get selection position
Created June 16, 2020 00:40
get selection position
var selectedLayers = context.selection;
for (var i = 0, n = selectedLayers.count(); i < n; i++) {
var layer = selectedLayers[i];
console.log(layer.frame().x());
console.log(layer.frame().y());
}
@janily
janily / get selection style
Last active June 16, 2020 01:12
get selection style
let sketch = require('sketch')
let doc = sketch.getSelectedDocument()
let selection = doc.selectedLayers.layers[0] //basic rect layer
let randomRadius = Math.round((Math.random()*100))
console.log("randomRadius: " + randomRadius)
selection.points.forEach(point => point.cornerRadius = randomRadius)
selection.sketchObject.setFixedRadius(randomRadius)
A list of sketch scripts
const tokenArray = [
{ name: 'color-background-default', value: '#f5f7fa'},
{ name: 'color-background-white', value: '#fff'},
{ name: 'color-background-dark', value: '#202d40'},
{ name: 'color-background-tooltip', value: '#202d40'},
{ name: 'color-background-message-warning', value: '#fffbe5'},
{ name: 'color-background-message-success', value: '#f2ffe0'},
{ name: 'color-background-message-error', value: '#fff0f0'},
{ name: 'color-background-message-info', value: '#e6f7ff'},
{ name: 'color-background-list-row-hover', value: '#f5f7fa'},
@janily
janily / 0 Generate icons collection.sketchscript
Created June 14, 2020 03:45 — forked from tankxu/0 Generate icons collection.sketchscript
Use this script to genrate icons collection artboard for your icon sketch library.
const sketch = require("sketch")
const document = sketch.getSelectedDocument()
const selection = document.selectedLayers.layers
const Group = sketch.Group
const Style = sketch.Style
const Rectangle = sketch.Rectangle
const Artboard = sketch.Artboard
const ShapePath = sketch.ShapePath
const Text = sketch.Text
const SymbolInstance = sketch.SymbolInstance
@janily
janily / sketch file json
Created June 11, 2020 06:23
sketch file json
var sketch = require('sketch')
var getSelectedDocument = require('sketch/dom').getSelectedDocument;
const document = getSelectedDocument().pages[0].layers;
console.info(JSON.stringify(document));
@janily
janily / add layer in selection
Created June 10, 2020 15:12
add layer in selection
var sketch = require('sketch')
var Style = sketch.Style
var Rectangle = sketch.Rectangle
var ShapePath = sketch.ShapePath
var doc = sketch.getSelectedDocument()
var selection = doc.selectedLayers
var myShape = new ShapePath({
name: 'my shape',
frame: new Rectangle(20,20,100,200),
@janily
janily / remove layer
Created June 10, 2020 12:54
remove layer
let sketch = require('sketch')
let doc = sketch.getSelectedDocument()
let selectedLayersObject = doc.selectedLayers
let selectedLayersArray = selectedLayersObject.layers
//console.log(selectedLayersArray[0])
selectedLayersArray.forEach(layer => {
//console.log(layer.layers)
layer.layers.forEach(lay => {
console.log(lay.remove())
@janily
janily / sketch setKey
Created June 6, 2020 14:12
setValue_forKey_onLayer_forPluginIdentifier
var sketch = context.api()
var document = sketch.selectedDocument;
var selection = document.selectedLayers;
var command = context.command;
var selectedLayer = context.document.selectedLayers().firstLayer()
console.log(selectedLayer)
@janily
janily / README.md
Created May 30, 2020 14:22 — forked from pbojinov/README.md
Two way iframe communication- Check out working example here: http://pbojinov.github.io/iframe-communication/

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.

Parent

Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')

iframe