Created
August 6, 2013 03:29
-
-
Save wilkerlucio/6161779 to your computer and use it in GitHub Desktop.
Photoshop Grid Generator
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
var DocumentArea = function(doc) { | |
this.doc = doc; | |
}; | |
DocumentArea.prototype.bounds = function() { | |
return [0, 0, this.doc.width, this.doc.height]; | |
}; | |
var DocumentArea = function(doc) { | |
this.doc = doc; | |
}; | |
DocumentArea.prototype.bounds = function() { | |
return [0, 0, this.doc.width, this.doc.height]; | |
}; | |
BOUND_LEFT = 0; | |
BOUND_TOP = 1; | |
BOUND_RIGHT = 2; | |
BOUND_BOTTOM = 3; | |
var buildArea = function(doc) { | |
try { | |
doc.selection.bounds; | |
return new SelectionArea(doc.selection); | |
} catch(e) { | |
return new DocumentArea(doc); | |
} | |
}; | |
if (app.documents.length > 0) { | |
var doc = app.activeDocument; | |
var area = buildArea(doc); | |
var numberColumns = parseInt(prompt("How many columns do you need?", 12)); | |
var bounds = area.bounds(); | |
var width = bounds[BOUND_RIGHT] - bounds[BOUND_LEFT]; | |
var columnWidth = width / numberColumns; | |
var left = bounds[BOUND_LEFT]; | |
for(var i = 1; i < numberColumns; i++) { | |
doc.guides.add(Direction.VERTICAL, i * columnWidth + left); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment