Copy link to clipboard
Copied
I'm not entirely sure of the scope of what's possible but I'm trying to do the following:
Pretext: I have 52 layers named a1 to z1 and also a2 to z2. Each layer has a letter corrseponding to its name. A2 is just a different letter A. The intention is to input a name and generate that name based on the text. I'm planning to print out peoples names that they input. But I don't want to manually sort out each name and each layer on every single order, and since print on demand sites wouldn't allow me to upload 52 pictures, sort and print based on someone's input I would have to at least somewhat do this normally. The name would display based one 1 then 2 then 1 then 2.
for example inputting ADAM, would select layer A1 then move, D2 then move, A2 then move, M1 then move. This is how I envision it, let me know if I'm on the right track please:
to simplify id set up each position from one to ten and just select that as a position based on the input length in the sequencer.
Can this be done in photoshop?
It will take time and effort to create automation for such a task. The investment in time and effort has to be balanced against the time and effort of doing this manually for the volume of orders received.
A different approach would be to create a separate square canvas file for each letter in the alphabet (all using the same canvas size and common baseline, same pixel size and resolution etc).
A script could open each required letter and stack the files horizontally to create a word.
Thi
...I have no access to the files on the onedrive server so I cannot test with them.
With a simple test file (with layers only for »a« through »f«) I was able to use the Script below to get an Array of Arrays (containing the Layer’s name, the index [which can be used to address/select the layer], the bounds [which can be used to calculate the necessary offsets]) in which the layers starting with the intended letter are being »rotated« (see the multiple »e«s for example).
// 2023, use it at your
...
Copy link to clipboard
Copied
In my test that code performed fine, could you please post screenshots with the pertinent Panels (Toolbar, Layers, Options Bar, …) visible?
Copy link to clipboard
Copied
It's no problem but for your knowledge seek I suppose. I run the code I specified earlier. Without trim. It changes the canvas size to the letters that have been chosen. Then I run the trim script, looks like this:
Copy link to clipboard
Copied
I would recommend doing away with the Background Layer and Delete Hidden Layers.
Copy link to clipboard
Copied
If you want to invest more time please try the following code.
With a simple test-file it seems to perform fairly speedy.
edit: I had forgotten to remove the revert I used while testing and I updated the code accordingly.
// collect layers named »letterNumber« and get an array according to a string, then duplicate and move the layers accordingly;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
// revert;
//executeAction( stringIDToTypeID( "revert" ), undefined, DialogModes.NO );
var myDocument = activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
////////////////////////////////////
var theString = prompt("Enter a name:", "badebefefefe");
if (theString) {
var theLayers = collectLayersBounds ();
theLayers.sort();
var theRegExp = /^\D\d$/i;
// create arrays sorted by initial letter;
var theArrays = new Array;
for (var m = 0; m < theLayers.length; m++) {
var thisOne = theLayers[m];
var theCheck = false;
if (thisOne[0].match(theRegExp) != null) {
var theLetter = String(thisOne[0].match(/^\D/i));
for (var n = 0; n < theArrays.length; n++) {
if (theArrays[n][0][0][0] == theLetter) {
theArrays[n].push(thisOne);
var theCheck = true
}
};
if (theCheck != true) {theArrays.push([thisOne])};
}
};
// check string against array;
var theResult = new Array;
for (var o = 0; o < theString.length; o++) {
var thisOne = theString[o];
for (var p = 0; p < theArrays.length; p++) {
if (theArrays[p][0][0][0].match(new RegExp (thisOne, "i")) != null) {
theResult.push (theArrays[p][0])
var theStuff = theArrays[p].splice(0,1);
theArrays[p].push(theStuff[0]);
}
};
};
if (theResult.length > 0) {
app.togglePalettes;
////////////////////////////////////
var theX = 0;
var theY = 0;
for (var q = 0; q < theResult.length; q++) {
var thisOne = theResult[q];
duplicateMoveRotateScale(true, thisOne[1], theX-thisOne[2][0], thisOne[2][1]*(-1), 100, 100, 0);
theX = theX+(thisOne[2][2]-thisOne[2][0]);
theY = Math.max(theY, thisOne[2][3]-thisOne[2][1]);
var thisLayerId = getLayerId();
moveLayerTo (thisLayerId, getTopLayerIndex ()+1);
};
if (theX != 0 && theY != 0) {myDocument.crop([0,0,theX,theY])};
};
app.togglePalettes;
};
////////////////////////////////////
app.preferences.rulerUnits = originalRulerUnits;
};
////// collect layers //////
function collectLayersBounds () {
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
theLayers.push([theName, theID, theseBounds])
};
}
catch (e) {};
};
return theLayers
};
////// based on code by mike hale, via paul riggott //////
function selectLayerByID(id,add){
try {
add = undefined ? add = false:add
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID("Lyr "), id);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
try{
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message);
}
} catch (e) {}
};
////// duplicate layer and move, rotate and scale it //////
function duplicateMoveRotateScale (copyOrNot, theID, theX, theY, theScaleX, theScaleY, theRotation) {
selectLayerByID(theID,false);
/*smartify (activeDocument.activeLayer);
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), charIDToTypeID ("LyrI"));
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
d = executeActionGet(ref);
var theID = d.getInteger(charIDToTypeID('LyrI'));*/
try{
var idTrnf = charIDToTypeID( "Trnf" );
var desc10 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref6 = new ActionReference();
//ref6.putIdentifier( charIDToTypeID( "Lyr " ), theID );
ref6.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc10.putReference( idnull, ref6 );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc10.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc11 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idHrzn, idPxl, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc11.putUnitDouble( idVrtc, idPxl, theY );
var idOfst = charIDToTypeID( "Ofst" );
desc10.putObject( idOfst, idOfst, desc11 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc10.putUnitDouble( idWdth, idPrc, theScaleX );
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc10.putUnitDouble( idHght, idPrc, theScaleY );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc10.putUnitDouble( idAngl, idAng, theRotation );
var idIntr = charIDToTypeID( "Intr" );
var idIntp = charIDToTypeID( "Intp" );
var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );
desc10.putEnumerated( idIntr, idIntp, idbicubicAutomatic );
var idCpy = charIDToTypeID( "Cpy " );
desc10.putBoolean( idCpy, copyOrNot );
executeAction( idTrnf, desc10, DialogModes.NO );
return theID
} catch (e) {}
};
////// by mike hale, via paul riggott //////
function getLayerIndex(theId){
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('itemIndex'));
// ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
ref.putIdentifier(charIDToTypeID("Lyr "), theId);
d = executeActionGet(ref);
return (d.getInteger(stringIDToTypeID('itemIndex'))-1);
};
////// move active layer in front of other layer in layer stack //////
function moveLayerTo (thisLayerId, theIndex) {
selectLayerByID(thisLayerId, false);
var idlayer = stringIDToTypeID( "layer" );
var desc58 = new ActionDescriptor();
var ref19 = new ActionReference();
ref19.putEnumerated( idlayer, stringIDToTypeID( "ordinal" ), stringIDToTypeID( "targetEnum" ) );
desc58.putReference( stringIDToTypeID( "null" ), ref19 );
var ref20 = new ActionReference();
ref20.putIndex( idlayer, theIndex );
desc58.putReference( stringIDToTypeID( "to" ), ref20 );
desc58.putBoolean( stringIDToTypeID( "adjustment" ), false );
desc58.putInteger( stringIDToTypeID( "version" ), 5 );
var list11 = new ActionList();
list11.putInteger(thisLayerId);
desc58.putList( stringIDToTypeID( "layerID" ), list11 );
executeAction( stringIDToTypeID( "move" ), desc58, DialogModes.NO );
};
////// get active layer’s id //////
function getLayerId () {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
//var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
/*var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
var theWidth = theseBounds[2]-theseBounds[0];
var theHeight = theseBounds[3]-theseBounds[1];*/
//return [theName, theID, theseBounds, theWidth, theHeight]
return theID
};
////// number of layers //////
function getTopLayerIndex () {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
var numberOfLayers = docDesc.getInteger(stringIDToTypeID("numberOfLayers"));
var background = docDesc.getBoolean(stringIDToTypeID("hasBackgroundLayer"));
if (background == false) {numberOfLayers--};
return numberOfLayers
};
updated 2024-01-07