
Adobe Photoshop CS3
JavaScript Scripting Reference
JavaScript Object Reference 169
var startDisplayDialogs = app.displayDialogs
// Set Adobe Photoshop CS3 to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO
//Close all the open documents
while (app.documents.length) {
app.activeDocument.close()
}
//Create variables for the 800 pixel board divided in even 100 x 100 squares
var docSize = 800
var cells = 8
var cellSize = docSize / cells
// create a new document
var checkersDoc = app.documents.add(docSize, docSize, 72, "Checkers")
// Create a variable to use for selecting the checker board
// That allows me to shift the selection one square to the right
//on every other row, and then shift back for the rows in between.
var shiftIt = true
// loop through vertically to create the first row
for (var v = 0; v < docSize; v += cellSize) {
// Switch the shift for a new row
shiftIt = !shiftIt
// loop through horizontally
for (var h = 0; h < docSize; h += (cellSize * 2)) {
// push over the cellSize to start with only
if (shiftIt && h == 0) {
h += cellSize
}
// Select a square
selRegion = Array(Array(h, v),
Array(h + cellSize, v),
Array(h + cellSize, v + cellSize),
Array(h, v + cellSize),
Array(h, v))
// In the first ineration of the loop, start the selection
//In subsequent iterations, use the EXTEND constant value
//of the select() method to add to the selection (in the loop’s else clause)
if (h == 0 && v == 0) {
checkersDoc.selection.select(selRegion)
} else {
checkersDoc.selection.select(selRegion, SelectionType.EXTEND)
}
// turn this off for faster execution
// turn this on for debugging
WaitForRedraw()
}
}