Skip to content

Instantly share code, notes, and snippets.

@wilkerlucio
Created August 6, 2013 03:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wilkerlucio/6161779 to your computer and use it in GitHub Desktop.
Save wilkerlucio/6161779 to your computer and use it in GitHub Desktop.
Photoshop Grid Generator
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