Things like this are super easy to do with the ScriptingListener plugin — takes literally a minute or two.
So I have an image with a layer (as a smart object) that I want to rotate:
I rotate the layer the way I want: exact numbers aren't important now. And then save it as a .png
ScriptingListener will generate a .log
file on the desktop. There's some garbage but I know I need 2 things: a transform and a save. So I look for a block with some numbers and a block with a save path. Here are they:
// =======================================================
var idTrnf = charIDToTypeID( "Trnf" );
var desc12 = new ActionDescriptor();
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsi = charIDToTypeID( "Qcsi" );
desc12.putEnumerated( idFTcs, idQCSt, idQcsi );
var idPstn = charIDToTypeID( "Pstn" );
var desc13 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idHrzn, idPxl, 251.985380 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idVrtc, idPxl, 284.023392 );
var idPnt = charIDToTypeID( "Pnt " );
desc12.putObject( idPstn, idPnt, desc13 );
var idOfst = charIDToTypeID( "Ofst" );
var desc14 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc14.putUnitDouble( idHrzn, idPxl, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc14.putUnitDouble( idVrtc, idPxl, -0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc12.putObject( idOfst, idOfst, desc14 );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc12.putUnitDouble( idAngl, idAng, 7.740591 );
executeAction( idTrnf, desc12, DialogModes.NO );
// =======================================================
var idsave = charIDToTypeID( "save" );
var desc21 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc22 = new ActionDescriptor();
var idMthd = charIDToTypeID( "Mthd" );
var idPNGMethod = stringIDToTypeID( "PNGMethod" );
var idquick = stringIDToTypeID( "quick" );
desc22.putEnumerated( idMthd, idPNGMethod, idquick );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIN = charIDToTypeID( "PGIN" );
desc22.putEnumerated( idPGIT, idPGIT, idPGIN );
var idPNGf = charIDToTypeID( "PNGf" );
var idPNGf = charIDToTypeID( "PNGf" );
var idPGAd = charIDToTypeID( "PGAd" );
desc22.putEnumerated( idPNGf, idPNGf, idPGAd );
var idCmpr = charIDToTypeID( "Cmpr" );
desc22.putInteger( idCmpr, 6 );
var idPNGF = charIDToTypeID( "PNGF" );
desc21.putObject( idAs, idPNGF, desc22 );
var idIn = charIDToTypeID( "In " );
desc21.putPath( idIn, new File( "E:\\temp\\del\\test\\01.png" ) );
var idDocI = charIDToTypeID( "DocI" );
desc21.putInteger( idDocI, 821 );
var idCpy = charIDToTypeID( "Cpy " );
desc21.putBoolean( idCpy, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveBegin = stringIDToTypeID( "saveBegin" );
desc21.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc21, DialogModes.NO );
Now it's a matter of converting this to a function. Final script and result:
var i;
var copies = 64;
var angle = 360 / copies;
for (i = 0; i < copies; i++) {
rotate(angle, i)
}
function rotate(angle, i)
{
// =======================================================
var idTrnf = charIDToTypeID("Trnf");
var desc12 = new ActionDescriptor();
var idFTcs = charIDToTypeID("FTcs");
var idQCSt = charIDToTypeID("QCSt");
var idQcsi = charIDToTypeID("Qcsi");
desc12.putEnumerated(idFTcs, idQCSt, idQcsi);
var idPstn = charIDToTypeID("Pstn");
var desc13 = new ActionDescriptor();
var idHrzn = charIDToTypeID("Hrzn");
var idPxl = charIDToTypeID("#Pxl");
desc13.putUnitDouble(idHrzn, idPxl, 251.985380);
var idVrtc = charIDToTypeID("Vrtc");
var idPxl = charIDToTypeID("#Pxl");
desc13.putUnitDouble(idVrtc, idPxl, 284.023392);
var idPnt = charIDToTypeID("Pnt ");
desc12.putObject(idPstn, idPnt, desc13);
var idOfst = charIDToTypeID("Ofst");
var desc14 = new ActionDescriptor();
var idHrzn = charIDToTypeID("Hrzn");
var idPxl = charIDToTypeID("#Pxl");
desc14.putUnitDouble(idHrzn, idPxl, 0.000000);
var idVrtc = charIDToTypeID("Vrtc");
var idPxl = charIDToTypeID("#Pxl");
desc14.putUnitDouble(idVrtc, idPxl, -0.000000);
var idOfst = charIDToTypeID("Ofst");
desc12.putObject(idOfst, idOfst, desc14);
var idAngl = charIDToTypeID("Angl");
var idAng = charIDToTypeID("#Ang");
desc12.putUnitDouble(idAngl, idAng, angle);
executeAction(idTrnf, desc12, DialogModes.NO);
// =======================================================
var idsave = charIDToTypeID("save");
var desc21 = new ActionDescriptor();
var idAs = charIDToTypeID("As ");
var desc22 = new ActionDescriptor();
var idMthd = charIDToTypeID("Mthd");
var idPNGMethod = stringIDToTypeID("PNGMethod");
var idquick = stringIDToTypeID("quick");
desc22.putEnumerated(idMthd, idPNGMethod, idquick);
var idPGIT = charIDToTypeID("PGIT");
var idPGIT = charIDToTypeID("PGIT");
var idPGIN = charIDToTypeID("PGIN");
desc22.putEnumerated(idPGIT, idPGIT, idPGIN);
var idPNGf = charIDToTypeID("PNGf");
var idPNGf = charIDToTypeID("PNGf");
var idPGAd = charIDToTypeID("PGAd");
desc22.putEnumerated(idPNGf, idPNGf, idPGAd);
var idCmpr = charIDToTypeID("Cmpr");
desc22.putInteger(idCmpr, 6);
var idPNGF = charIDToTypeID("PNGF");
desc21.putObject(idAs, idPNGF, desc22);
var idIn = charIDToTypeID("In ");
desc21.putPath(idIn, new File("E:\\temp\\del\\test\\F22_"+pad(i,4)+".png"));
var idDocI = charIDToTypeID("DocI");
desc21.putInteger(idDocI, 821);
var idCpy = charIDToTypeID("Cpy ");
desc21.putBoolean(idCpy, true);
var idsaveStage = stringIDToTypeID("saveStage");
var idsaveStageType = stringIDToTypeID("saveStageType");
var idsaveBegin = stringIDToTypeID("saveBegin");
desc21.putEnumerated(idsaveStage, idsaveStageType, idsaveBegin);
executeAction(idsave, desc21, DialogModes.NO);
}
function pad(n, width, z)
{
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}