Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!
#target photoshop // MAC Finder ou WINDOWS Explorer : double click
app.bringToFront(); // Photoshop foreground
// User's preferences must probably be changed
var ruleUnit = app.preferences.rulerUnits;
var typeUnit = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.POINTS;
app.preferences.typeUnits = TypeUnits.POINTS;
// Variable & Constant declaration
const BLACK = new SolidColor(); // Color of the font is black
BLACK.rgb.hexValue = '000000';
main();
app.preferences.rulerUnits = ruleUnit;
app.preferences.typeUnits = typeUnit;
function main() {
var docRef = documents.add (1618,268,72,"Grid",NewDocumentMode.RGB,DocumentFill.WHITE);
for (var i = 0;i < 10;i++) {
var square = app.activeDocument;
var x1 = 65 + i*150;
var y1 = 60;
var x2 = x1+150;
var y2 = y1 + 150;
square.selection.select([ [x1,y1], [x2,y1], [x2,y2], [x1,y2] ]);
stroke();
square.selection.deselect()
}
for (var i = 0;i < 10;i++) {
var artLayerRef = app.activeDocument.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;
var textItemRef = artLayerRef.textItem;
textItemRef.contents = i+1;
textItemRef.TextType = TextType.PARAGRAPHTEXT;
textItemRef.color = BLACK;
textItemRef.font = "BodoniMT"; // BodoniMT-Bold
textItemRef.size = 95;
textItemRef.justification=Justification.CENTER;
posX = 141 + i * 150;
posY = 160;
var locText = new Array(posX, posY);
textItemRef.position = locText;
}
docRef.flatten();
var docArrow = documents.add (96,34,72,"Arrow",NewDocumentMode.RGB,DocumentFill.TRANSPARENT);
var a= Array(0, 20);
var b = Array(73,20);
var c = Array(63, 33);
var d = Array(96, 17);
var e = Array(63,0);
var f = Array(73, 14);
var g = Array(0, 14);
var myRegion = Array(a, b, c, d,e,f,g);
docArrow.selection.select(myRegion);
docArrow.selection.fill(BLACK);
docArrow.selection.selectAll();
docArrow.selection.copy();
docArrow.close(SaveOptions.DONOTSAVECHANGES);
docRef.paste();
var docArrow1 = docRef.activeLayer;
docRef.paste();
docArrow1.translate(-295,0);
var docArrow2 = docRef.activeLayer;
docArrow2.translate(-140,0);
docRef.flatten();
}
// =======================================================
function stroke() {
var idStrk = charIDToTypeID( "Strk" );
var desc13 = new ActionDescriptor();
var idWdth = charIDToTypeID( "Wdth" );
desc13.putInteger( idWdth, 3 );
var idLctn = charIDToTypeID( "Lctn" );
var idStrL = charIDToTypeID( "StrL" );
var idInsd = charIDToTypeID( "Insd" );
desc13.putEnumerated( idLctn, idStrL, idInsd );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc13.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc13.putEnumerated( idMd, idBlnM, idNrml );
var idClr = charIDToTypeID( "Clr " );
var desc14 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc14.putDouble( idRd, 0.000000 );
var idGrn = charIDToTypeID( "Grn " );
desc14.putDouble( idGrn, 0.000000 );
var idBl = charIDToTypeID( "Bl " );
desc14.putDouble( idBl, 0.000000 );
var idRGBC = charIDToTypeID( "RGBC" );
desc13.putObject( idClr, idRGBC, desc14 );
executeAction( idStrk, desc13, DialogModes.NO );
}
I have no experience in photoshop, but I do got experience with programming languages!For your information, there is a very precise and especially very fast solution: the Photoshop scripting languages (AppleScript, VBScript and especially Javascript). This solution is not within the reach of a beginner, but you should know that it exists and that it can be a wonderful tool for a job like yours.
i-th image: numbers goes from i to i+9
I do agree! The arrows are always at the same place.It is not difficult to modify this script, but I want to be sure of the algorithm you need.
The script can ask the user to declare a value for "i" first, then creates i .PNG files from 1..10 to i..i+9 in a subfolder. Do you agree with this algorithm.
Question : are the arrows always at the same place ?
The template of the graphic in this post is just one of several templates that I'll create for math teaching purposes. The numbers that appears in each template are going to vary in a wide range in order to create hundreds of different images.Why would you use scripting for built in functions?
There are so many simple ways to do the same thing, you could even use a paint brush to make the squares.
I give up...
#target photoshop // MAC Finder ou WINDOWS Explorer : double click
app.bringToFront(); // Photoshop foreground
// User's preferences must probably be changed
var ruleUnit = app.preferences.rulerUnits;
var typeUnit = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.POINTS;
app.preferences.typeUnits = TypeUnits.POINTS;
// Variable declaration
const BLACK = new SolidColor(); // Color of the font is black
BLACK.rgb.hexValue = '000000';
var saveFolder = Folder(File($.fileName).path + "/save");
if (!saveFolder.exists) saveFolder.create();
var pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.interlaced = false; // Not interlaced
pngSaveOptions.compression=0; // without compression)
var step = -1;
main();
alert("Your files were saved in the folder [" + saveFolder + "]");
app.preferences.rulerUnits = ruleUnit;
app.preferences.typeUnits = typeUnit;
function main() {
loop = prompt("How many rows do you want to create?", "");
if (loop === null){return;} // Cancel
for (k=0;k<loop;k++) {
step+=1;
var docRef = documents.add (1618,268,72,"Grid",NewDocumentMode.RGB,DocumentFill.WHITE);
for (var i = 0;i < 10;i++) {
var square = app.activeDocument;
var x1 = 65 + i*150;
var y1 = 60;
var x2 = x1+150;
var y2 = y1 + 150;
square.selection.select([ [x1,y1], [x2,y1], [x2,y2], [x1,y2] ]);
stroke();
square.selection.deselect()
}
for (var i = 0;i < 10;i++) {
var artLayerRef = app.activeDocument.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;
var textItemRef = artLayerRef.textItem;
textItemRef.contents = i+1+step;
textItemRef.TextType = TextType.PARAGRAPHTEXT;
textItemRef.color = BLACK;
textItemRef.font = "BodoniMT"; // BodoniMT-Bold
textItemRef.size = 95;
textItemRef.justification=Justification.CENTER;
posX = 141 + i * 150;
posY = 160;
var locText = new Array(posX, posY);
textItemRef.position = locText;
}
docRef.flatten();
var docArrow = documents.add (96,34,72,"Arrow",NewDocumentMode.RGB,DocumentFill.TRANSPARENT);
var a= Array(0, 20);
var b = Array(73,20);
var c = Array(63, 33);
var d = Array(96, 17);
var e = Array(63,0);
var f = Array(73, 14);
var g = Array(0, 14);
var myRegion = Array(a, b, c, d,e,f,g);
docArrow.selection.select(myRegion);
docArrow.selection.fill(BLACK);
docArrow.selection.selectAll();
docArrow.selection.copy();
docArrow.close(SaveOptions.DONOTSAVECHANGES);
docRef.paste();
var docArrow1 = docRef.activeLayer;
docRef.paste();
docArrow1.translate(-295,0);
var docArrow2 = docRef.activeLayer;
docArrow2.translate(-140,0);
docRef.flatten();
var saveFile = File(saveFolder + "/" + "row" + k + ".png");
docRef.saveAs(saveFile, pngSaveOptions);
docRef.close(SaveOptions.DONOTSAVECHANGES);
}
}
// =======================================================
function stroke() {
var idStrk = charIDToTypeID( "Strk" );
var desc13 = new ActionDescriptor();
var idWdth = charIDToTypeID( "Wdth" );
desc13.putInteger( idWdth, 3 );
var idLctn = charIDToTypeID( "Lctn" );
var idStrL = charIDToTypeID( "StrL" );
var idInsd = charIDToTypeID( "Insd" );
desc13.putEnumerated( idLctn, idStrL, idInsd );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc13.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc13.putEnumerated( idMd, idBlnM, idNrml );
var idClr = charIDToTypeID( "Clr " );
var desc14 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc14.putDouble( idRd, 0.000000 );
var idGrn = charIDToTypeID( "Grn " );
desc14.putDouble( idGrn, 0.000000 );
var idBl = charIDToTypeID( "Bl " );
desc14.putDouble( idBl, 0.000000 );
var idRGBC = charIDToTypeID( "RGBC" );
desc13.putObject( idClr, idRGBC, desc14 );
executeAction( idStrk, desc13, DialogModes.NO );
}