Set animation frame duration with scripting
From within PS, I want to be able to create animation frames from layers and then set the frame duration (frame delay)
This is what I have so far:
var frametime = 1.0 // 1 sec /frame
// create animation frames
createAnimationFromLayers();
// set frame timing
setFrameDuration(frameTime);
function createAnimationFromLayers()
{
// =======================================================
var id9070 = stringIDToTypeID( "animationFramesFromLayers" );
var desc1033 = new ActionDescriptor();
executeAction( id9070, desc1033, DialogModes.NO );
}
function selectAllFrames()
{
// =======================================================
var id3 = stringIDToTypeID( "animationSelectAll" );
var desc2 = new ActionDescriptor();
executeAction( id3, desc2, DialogModes.NO );
}
function setFrameDuration(num)
{
selectAllFrames()
// =======================================================
var id4 = charIDToTypeID( "setd" );
var desc3 = new ActionDescriptor();
var id5 = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var id6 = stringIDToTypeID( "animationFrameClass" );
var id7 = charIDToTypeID( "Ordn" );
var id8 = charIDToTypeID( "Trgt" );
ref1.putEnumerated( id6, id7, id8 );
desc3.putReference( id5, ref1 );
var id9 = charIDToTypeID( "T " );
var desc4 = new ActionDescriptor();
var id10 = stringIDToTypeID( "animationFrameDelay" );
desc4.putDouble( id10, num ); //num (duration in seconds)
var id11 = stringIDToTypeID( "animationFrameClass" );
desc3.putObject( id9, id11, desc4 );
executeAction( id4, desc3, DialogModes.NO );
}
What I want to know is this
- How can you open the animation window in scripting ( as it script will fail with it closed) - might have to add a try/catch for it otherwise
- Is it possible to loop over the animation frames like this: (I don't know the syntax I'm guessing)
for (var i = 0; i < numOFrames; i++)
{
app.activeDocument.animation.frames = 1.0;
}
