Skip to content

Instantly share code, notes, and snippets.

@cbguder
Created December 22, 2010 13:32
Show Gist options
  • Save cbguder/751500 to your computer and use it in GitHub Desktop.
Save cbguder/751500 to your computer and use it in GitHub Desktop.
960gs ExtendScript for Adobe Photoshop CS5
/*
* 960gs ExtendScript for Adobe Photoshop CS5
* Copyright (c) 2010 Can Berk Güder
*/
#target photoshop
var doc;
var w = new Window(
"dialog {\
text: '960gs',\
alignChildren: 'fill',\
vertical: Panel {\
text: 'Vertical Guides',\
alignChildren: 'right',\
colWidth: Group {\
st: StaticText { text: 'Column width:' },\
et: EditText { text: '60', characters: 5 }\
},\
numColumns: Group {\
st: StaticText { text: 'Number of columns:' },\
et: EditText { text: '12', characters: 5 }\
},\
gutterWidth: Group {\
st: StaticText { text: 'Gutter width:' },\
et: EditText { text: '20', characters: 5 }\
}\
},\
horizontal: Panel {\
text: 'Horizontal Guides',\
alignChildren: 'right',\
rowHeight: Group {\
st: StaticText { text: 'Row height:' },\
et: EditText { text: '20', characters: 5 }\
}\
},\
opts: Panel {\
text: 'Options',\
alignChildren: 'left',\
addVertical: Checkbox { text: 'Add vertical guides', value: true },\
addHorizontal: Checkbox { text: 'Add horizontal guides' },\
centerHorizontal: Checkbox { text: 'Center horizontally', value: true }\
},\
buttons: Group {\
alignment: 'center',\
okBtn: Button { text: 'OK', properties: { name: 'ok' }},\
cancelBtn: Button { text: 'Cancel', properties: { name: 'cancel' }}\
}\
}");
w.buttons.okBtn.onClick = function() {
if(w.opts.addVertical.value) {
var colWidth = Number(w.vertical.colWidth.et.text);
var numColumns = Number(w.vertical.numColumns.et.text);
if(colWidth > 0 && numColumns > 0) {
var gutterWidth = Number(w.vertical.gutterWidth.et.text);
var x = 0;
if(w.opts.centerHorizontal.value) {
var docWidth = doc.width.as('px');
var gridWidth = (numColumns * colWidth) + ((numColumns-1) * gutterWidth);
x = (docWidth - gridWidth) / 2;
}
if(gutterWidth > 0) {
for(var i = 0; i < numColumns; i++) {
doc.guides.add(Direction.VERTICAL, UnitValue(x, 'px'));
x += colWidth;
doc.guides.add(Direction.VERTICAL, UnitValue(x, 'px'));
x += gutterWidth;
}
} else {
for(var i = 0; i <= numColumns; i++) {
doc.guides.add(Direction.VERTICAL, UnitValue(x, 'px'));
x += colWidth;
}
}
}
}
if(w.opts.addHorizontal.value) {
var rowHeight = Number(w.horizontal.rowHeight.et.text);
if(rowHeight > 0) {
var docHeight = doc.height.as('px');
var y = rowHeight;
while(y < docHeight) {
doc.guides.add(Direction.HORIZONTAL, UnitValue(y, 'px'));
y += rowHeight;
}
}
}
w.close();
}
function main() {
try {
doc = app.activeDocument;
} catch(e) {
alert('No active document', '960gs', true);
return;
}
w.show();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment