This repository was archived by the owner on Jun 3, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +64
-61
lines changed
Sketch Commands.sketchplugin/Contents/Sketch Expand file tree Collapse file tree 5 files changed +64
-61
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // Distributes the selected elements horizontally, with the same distance beetween them.
2+ var onRun = function ( context ) {
3+ var sketch = require ( 'sketch' )
4+ var Document = sketch . Document
5+ var UI = sketch . UI
6+ var document = Document . getSelectedDocument ( )
7+ var selection = document . selectedLayers
8+
9+ function sort_by_position ( a , b ) {
10+ return a . frame . x - b . frame . x
11+ }
12+
13+ UI . getInputFromUser (
14+ "Spacing" ,
15+ {
16+ initialValue : 10 ,
17+ } ,
18+ ( err , value ) => {
19+ if ( err ) {
20+ return
21+ }
22+ var sorted_selection = selection . layers . sort ( sort_by_position )
23+ var first_element = sorted_selection [ 0 ]
24+ var left_position = first_element . frame . x
25+ sorted_selection . forEach ( layer => {
26+ layer . frame . x = left_position
27+ left_position = layer . frame . x + layer . frame . width + parseInt ( value )
28+ } )
29+ }
30+ )
31+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // Distributes the selected elements vertically, with the same distance beetween them.
2+ var onRun = function ( context ) {
3+ var sketch = require ( 'sketch' )
4+ var Document = sketch . Document
5+ var UI = sketch . UI
6+ var document = Document . getSelectedDocument ( )
7+ var selection = document . selectedLayers
8+
9+ function sort_by_position ( a , b ) {
10+ return a . frame . x - b . frame . x
11+ }
12+
13+ UI . getInputFromUser (
14+ "Spacing" ,
15+ {
16+ initialValue : 10 ,
17+ } ,
18+ ( err , value ) => {
19+ if ( err ) {
20+ return
21+ }
22+ var sorted_selection = selection . layers . sort ( sort_by_position )
23+ var first_element = sorted_selection [ 0 ]
24+ var top_position = first_element . frame . y
25+ sorted_selection . forEach ( layer => {
26+ layer . frame . y = top_position
27+ top_position = layer . frame . y + layer . frame . height + parseInt ( value )
28+ } )
29+ }
30+ )
31+ }
Original file line number Diff line number Diff line change 1515 "name" : " Space Horizontal" ,
1616 "identifier" : " spacehorizontal" ,
1717 "shortcut" : " " ,
18- "script" : " Align/Space Horizontal.cocoascript "
18+ "script" : " Align/Space Horizontal.js "
1919 },
2020 {
2121 "name" : " Space Vertical" ,
2222 "identifier" : " spacevertical" ,
2323 "shortcut" : " " ,
24- "script" : " Align/Space Vertical.cocoascript "
24+ "script" : " Align/Space Vertical.js "
2525 },
2626 {
2727 "name" : " Alpha…" ,
You can’t perform that action at this time.
0 commit comments