Skip to main content
Known Participant
October 23, 2013
Resuelto

Are there Javascript hooks to manipulate the timeline?

  • October 23, 2013
  • 1 respuesta
  • 2684 visualizaciones

Is there an API for manipulating the timeline?  I didn't see anything about it in the JS API pdf, and after briefly scanning the object hierarchy in the toolkit, I didn't see it.  I'd like to be able to create new frames, jump to specific frames, remove frames, etc. 

Este tema ha sido cerrado para respuestas.
Mejor respuesta de pixxxelschubser

I think – only with script listener code.

For example you can do  this:

// go to frame number 2

var jumpToFrameNumber = 2; // counts from 1

var desc = new ActionDescriptor();

var ref1 = new ActionReference();

ref1.putIndex( stringIDToTypeID( "animationFrameClass" ), jumpToFrameNumber );

desc.putReference( charIDToTypeID( "null" ), ref1 );

executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

// delete active frame

var desc1 = new ActionDescriptor();

var ref2 = new ActionReference();

ref2.putEnumerated( stringIDToTypeID( "animationFrameClass" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

desc1.putReference( charIDToTypeID( "null" ), ref2 );

executeAction( charIDToTypeID( "Dlt " ), desc1, DialogModes.NO );

Also you can do something like this:

executeAction( stringIDToTypeID( "convertTimeline" ), new ActionDescriptor(), DialogModes.NO );

// or

//executeAction( stringIDToTypeID( "convertAnimation" ), new ActionDescriptor(), DialogModes.NO );

// and this

// the name say all

executeAction( stringIDToTypeID( "animationFramesFromLayers" ), new ActionDescriptor(), DialogModes.NO );

Have fun

1 respuesta

pixxxelschubser
Community Expert
Community Expert
October 23, 2013

I think – only with script listener code.

For example you can do  this:

// go to frame number 2

var jumpToFrameNumber = 2; // counts from 1

var desc = new ActionDescriptor();

var ref1 = new ActionReference();

ref1.putIndex( stringIDToTypeID( "animationFrameClass" ), jumpToFrameNumber );

desc.putReference( charIDToTypeID( "null" ), ref1 );

executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

// delete active frame

var desc1 = new ActionDescriptor();

var ref2 = new ActionReference();

ref2.putEnumerated( stringIDToTypeID( "animationFrameClass" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

desc1.putReference( charIDToTypeID( "null" ), ref2 );

executeAction( charIDToTypeID( "Dlt " ), desc1, DialogModes.NO );

Also you can do something like this:

executeAction( stringIDToTypeID( "convertTimeline" ), new ActionDescriptor(), DialogModes.NO );

// or

//executeAction( stringIDToTypeID( "convertAnimation" ), new ActionDescriptor(), DialogModes.NO );

// and this

// the name say all

executeAction( stringIDToTypeID( "animationFramesFromLayers" ), new ActionDescriptor(), DialogModes.NO );

Have fun

Known Participant
October 24, 2013

I've installed the script listener plugin and that seems to work great.  Thank you.  One question though.  How do I figure out commands the script listener won't normally listen for?  For example, I can add frames and select frames and see that in the log, but how can I figure out how many frames are already there? 

Inspiring
October 24, 2013

I don't think there is a short easy way to explain how to work with Action Manager( other than mining the scriptlistener log ). And there isn't much offical documentaion on using Action Manager.

Here is how to get the number of frames and the framerate.

function GetFrameCount(){

    var ref = new ActionReference();

     ref.putProperty( charIDToTypeID( 'Prpr' ), stringIDToTypeID( "frameCount" ) );

     ref.putClass( stringIDToTypeID( "timeline" ) );

     var desc = new ActionDescriptor();

     desc.putReference( charIDToTypeID( 'null' ), ref );

     var resultDesc = executeAction( charIDToTypeID( 'getd' ), desc, DialogModes.NO );

    

     return resultDesc.getInteger( stringIDToTypeID( "frameCount" ) );

};

function GetFrameRate(){

    var ref = new ActionReference();

     ref.putProperty( charIDToTypeID( 'Prpr' ), stringIDToTypeID("documentTimelineSettings") );

      ref.putClass( stringIDToTypeID( "timeline" ) );

     var desc = new ActionDescriptor();

     desc.putReference( charIDToTypeID( 'null' ), ref );

     var resultDesc = executeAction( charIDToTypeID( 'getd' ), desc, DialogModes.NO );

     return resultDesc.getDouble( stringIDToTypeID('frameRate') );

};