Created
April 27, 2017 02:45
-
-
Save willvincent/379fe84ffd46f39f2170e30a4de883cc to your computer and use it in GitHub Desktop.
custom plugin code for sketch
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 doc = context.document; | |
var page = doc.currentPage(); | |
var current_artboard = page.currentArtboard(); | |
var grid_width = [[doc askForUserInput:"How wide do you want your grid to be?" initialValue:"960"] integerValue] | |
var column_count = [[doc askForUserInput:"How many columns do you want?" initialValue:"12"] integerValue] | |
var gutter_width = [[doc askForUserInput:"How wide do you want your gutters to be?" initialValue:"20"] integerValue] | |
if (grid_width != 0 && column_count != 0 && current_artboard != null) { | |
var horizontal_rulers = [current_artboard horizontalRulerData] | |
var gutter_count = column_count + 1; | |
var space_for_columns = grid_width - (gutter_count * gutter_width) | |
var column_width = space_for_columns / column_count | |
var frame_center = [[current_artboard frame] width] / 2 | |
var start_grid_at = frame_center - (grid_width / 2) | |
var ruler_count = (column_count * 2) + 2 | |
for (var i=0; i < [ruler_count]; i++){ | |
[horizontal_rulers addGuideWithValue:start_grid_at] | |
if ((i % 2) == 0) { | |
start_grid_at += gutter_width | |
} else { | |
start_grid_at += column_width | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment