Skip to main content
Participant
March 14, 2023
Answered

How to get the seconds on a frame from the timeline

  • March 14, 2023
  • 2 replies
  • 918 views

We use the Frame Animation Timline to animate some things for our project, and we want to write a JavaScript tool to export the frame timings to a format that can be read by the rest of our content pipeline. 

 

With the script logging plugin, I've managed to capture how the data is set. But admittedly don't know how to go about pulling the data out of the currently selected frame. 

var idsetd = charIDToTypeID( "setd" );
    var desc230 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref1.putEnumerated( idanimationFrameClass, idOrdn, idTrgt );
    desc230.putReference( idnull, ref1 );
    var idT = charIDToTypeID( "T   " );
        var desc231 = new ActionDescriptor();
        var idanimationFrameDelay = stringIDToTypeID( "animationFrameDelay" );
        desc231.putDouble( idanimationFrameDelay, 1.000000 );
    var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
    desc230.putObject( idT, idanimationFrameClass, desc231 );
executeAction( idsetd, desc230, DialogModes.NO );

 

This topic has been closed for replies.
Correct answer HVStudios

With the help of c.pfaffenbickler, was able to get something put together. Here was my final result to get the frame time of the currently select frame. 

function GetFrameTime()
{
    var r = new ActionReference();
    r.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('animationFrameDelay'));
    r.putClass(stringIDToTypeID('animationFrameClass'));
    var ret = executeActionGet(r);
    return ret.getDouble(stringIDToTypeID('animationFrameDelay'));
}

 

2 replies

HVStudiosAuthorCorrect answer
Participant
March 15, 2023

With the help of c.pfaffenbickler, was able to get something put together. Here was my final result to get the frame time of the currently select frame. 

function GetFrameTime()
{
    var r = new ActionReference();
    r.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('animationFrameDelay'));
    r.putClass(stringIDToTypeID('animationFrameClass'));
    var ret = executeActionGet(r);
    return ret.getDouble(stringIDToTypeID('animationFrameDelay'));
}

 

c.pfaffenbichler
Community Expert
Community Expert
March 15, 2023

I don’t know who originally presented this code, I cannot locate the thread over on ps-scripts.com anymore. 

function getFrameRate() {
   
   var actionRef = new ActionReference();
   actionRef.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID("frameRate"));
   actionRef.putClass(stringIDToTypeID("timeline"));

   var desc=new ActionDescriptor();
   desc.putReference(charIDToTypeID('null'), actionRef);
         
   var TC=executeAction(charIDToTypeID('getd'), desc, DialogModes.NO);
   var frameRate=TC.getDouble(stringIDToTypeID("frameRate"));

   return frameRate;
}

function getFrame(IO) {

   if (IO == "in") var tIO = stringIDToTypeID("workInTime");
   if (IO == "out") var tIO = stringIDToTypeID("workOutTime");
   if (IO == "playHead") var tIO = stringIDToTypeID("time");

   var fr = 0;
   var secs = 0;
   var mins = 0;
   var hrs = 0;
   var frRate = 30.0;
   
   var rate = stringIDToTypeID("frameRate");
   var frame = stringIDToTypeID("frame");
   var seconds = stringIDToTypeID("seconds");
   var minutes = stringIDToTypeID("minutes");
   var hours = stringIDToTypeID("hours");

   var tLine=stringIDToTypeID("timeline");
   var get=charIDToTypeID('getd');
   var nul=charIDToTypeID('null');
   var prop=charIDToTypeID('Prpr');
   
   var actionRef = new ActionReference();
   actionRef.putProperty(prop,tIO);
   actionRef.putClass(tLine);

   var desc=new ActionDescriptor();
   desc.putReference(nul, actionRef);
         
   var TC=executeAction(get,desc,DialogModes.NO);
   var TL=TC.getObjectValue(tIO);
   
   try {fr=TL.getInteger(frame);} catch(e){}
   try {secs=TL.getInteger(seconds);} catch(e){}
   try {mins=TL.getInteger(minutes);} catch(e){}
   try {hrs=TL.getInteger(hours);} catch(e){}
   frRate = TL.getDouble(rate);

   return hrs * 3600 * frRate + mins * 60 * frRate + secs * frRate + fr;

}
alert(getFrame("in"));
alert(getFrame("out"));
alert(getFrame("playHead"));

alert(getFrameRate());

 

HVStudiosAuthor
Participant
March 15, 2023

I don't think that's it. That looks like that's for the Video Timeline, since it has lead in/out times and everything. I'm trying to get the frame time from the Frame Animation timeline, the "animationFrameClass." At least when it came to some GoToFrame() stuff I saw in another thread, though they occupy the same space they are two rather seperate systems under the hood.