PhotoShop中创建棋盘格的脚本

来源:互联网 发布:阿里云搭建视频教程 编辑:程序博客网 时间:2024/05/01 18:31
// Save the current preferencesvar startRulerUnits = app.preferences.rulerUnitsvar startTypeUnits = app.preferences.typeUnitsvar startDisplayDialogs = app.displayDialogs// Set Adobe Photoshop CS5 to use pixels and display no dialogsapp.preferences.rulerUnits = Units.PIXELSapp.preferences.typeUnits = TypeUnits.PIXELSapp.displayDialogs = DialogModes.NO//Close all the open documentswhile (app.documents.length) {app.activeDocument.close()}//Create variables for the 800 pixel board divided in even 100 x 100 squaresvar docSize = 800var cells = 8var cellSize = docSize / cells// create a new documentvar 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 rowfor (var v = 0; v < docSize; v += cellSize) {// Switch the shift for a new rowshiftIt = !shiftIt// loop through horizontallyfor (var h = 0; h < docSize; h += (cellSize * 2)) {// push over the cellSize to start with onlyif (shiftIt && h == 0) {h += cellSize}// Select a squareselRegion = 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 debuggingWaitForRedraw()}}// Fill the current selection with the foreground colorcheckersDoc.selection.fill(app.foregroundColor)//Invert the selectioncheckersDoc.selection.invert()// Fill the new selection with the background colorcheckersDoc.selection.fill(app.backgroundColor)// Clear the selection to get rid of the non-printing borderscheckersDoc.selection.deselect()// Reset the application preferencesapp.preferences.rulerUnits = startRulerUnitsapp.preferences.typeUnits = startTypeUnitsapp.displayDialogs = startDisplayDialogs// A helper function for debugging// It also helps the user see what is going on// if you turn it off for this example you// get a flashing cursor for a number timefunction WaitForRedraw(){var eventWait = charIDToTypeID("Wait")var enumRedrawComplete = charIDToTypeID("RdCm")var typeState = charIDToTypeID("Stte")var keyState = charIDToTypeID("Stte")var desc = new ActionDescriptor()desc.putEnumerated(keyState, typeState, enumRedrawComplete)executeAction(eventWait, desc, DialogModes.NO)}

这里写图片描述

0 0
原创粉丝点击