0

I'm trying to rotate a layer for an animation of my profile picture (below)

The initial layer name is "_a_Original" New copies should be "_a_Copy (copynumber)"

The idea is to rotate 360 times, 1 degree each time.

How would I do that?

I tried this answer, but it didn't seem to work, any way I can fix this?

Icon

3
  • At the moment, I'm using photopea to do it since its easier to compile frames in my opinion
    – Cmb
    Sep 25, 2022 at 18:36
  • Hi Welcome to GDSE. This site is not a script writing service. Although scripting questions are allowed, you need to show what you have tried or what has failed.
    – Billy Kerr
    Sep 25, 2022 at 18:40
  • I've edited the question for what I've already tried, I've tried searching the issue, although I am unable to find any answers.
    – Cmb
    Sep 25, 2022 at 18:42

1 Answer 1

0

Even thought you've not showed what you've attempted, this is quite straight forward. Firstly, you need to do list activate the ScriptListener - which records blocks of code for you.

After that it's basically three things. Duplicating a the original layer, rotating it x degrees and then repeating that 359 other times.

So with just your image as a layer in Photoshop and nothing else:

// Define angle and number of frames
var rotationAngle = 36; // I've set it to 36 as 360 will take 10 longer!

// rename the original
app.activeDocument.activeLayer.name = "original";

// loop over that rotationAngle number of times
for (var i = 0; i < rotationAngle; i++)
{
  // Duplicate layers
  // This is scriptListener code
  var id1572 = charIDToTypeID( "Dplc" );
  var desc350 = new ActionDescriptor();
  var id1573 = charIDToTypeID( "null" );
  var ref184 = new ActionReference();
  var id1574 = charIDToTypeID( "Lyr " );
  var id1575 = charIDToTypeID( "Ordn" );
  var id1576 = charIDToTypeID( "Trgt" );
  ref184.putEnumerated( id1574, id1575, id1576 );
  desc350.putReference( id1573, ref184 );
  var id1577 = charIDToTypeID( "Nm  " );
  desc350.putString( id1577, i+1 );
  var id1578 = charIDToTypeID( "Vrsn" );
  desc350.putInteger( id1578, 2 );
  executeAction( id1572, desc350, DialogModes.NO );
}

// Loop over it AGAIN!
for (var i = 0; i < rotationAngle; i++)
{
  // grab each layer in turn and make it active
  var thisLayer = app.activeDocument.layers[i];
  app.activeDocument.activeLayer = thisLayer;

  // rotate image x degrees
  var idTrnf = charIDToTypeID( "Trnf" );
  var desc802 = new ActionDescriptor();
  var idnull = charIDToTypeID( "null" );
  var ref237 = new ActionReference();
  var idLyr = charIDToTypeID( "Lyr " );
  var idOrdn = charIDToTypeID( "Ordn" );
  var idTrgt = charIDToTypeID( "Trgt" );
  ref237.putEnumerated( idLyr, idOrdn, idTrgt );
  desc802.putReference( idnull, ref237 );
  var idFTcs = charIDToTypeID( "FTcs" );
  var idQCSt = charIDToTypeID( "QCSt" );
  var idQcsa = charIDToTypeID( "Qcsa" );
  desc802.putEnumerated( idFTcs, idQCSt, idQcsa );
  var idOfst = charIDToTypeID( "Ofst" );
  var desc803 = new ActionDescriptor();
  var idHrzn = charIDToTypeID( "Hrzn" );
  var idPxl = charIDToTypeID( "#Pxl" );
  desc803.putUnitDouble( idHrzn, idPxl, 0);
  var idVrtc = charIDToTypeID( "Vrtc" );
  var idPxl = charIDToTypeID( "#Pxl" );
  desc803.putUnitDouble( idVrtc, idPxl, 0);
  var idOfst = charIDToTypeID( "Ofst" );
  desc802.putObject( idOfst, idOfst, desc803 );
  var idAngl = charIDToTypeID( "Angl" );
  var idAng = charIDToTypeID( "#Ang" );
  desc802.putUnitDouble( idAngl, idAng, i );
  var idIntr = charIDToTypeID( "Intr" );
  var idIntp = charIDToTypeID( "Intp" );
  var idNrst = charIDToTypeID( "Nrst" );
  desc802.putEnumerated( idIntr, idIntp, idNrst );
  executeAction( idTrnf, desc802, DialogModes.NO );
}

// Bingo you're all done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.