Skip to main content
salithan73779666
Participating Frequently
October 31, 2017
Answered

Is there anyway to identify keyframe of timeline animation using JSX script?

  • October 31, 2017
  • 2 replies
  • 2073 views

I need to retrieve animation data of keyframes( Only keyframes ) of video animation
I am using following code to iterate timeline. But still, I couldn't identify keyframes

Is there any way to identify keyframes?

function gotoFrame(Seconds, Frame, frameRate) {

    var desc69 = new ActionDescriptor();

    var ref33 = new ActionReference();

    ref33.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('time'));

    ref33.putClass(stringIDToTypeID('timeline'));

    desc69.putReference(charIDToTypeID('null'), ref33);

    var desc70 = new ActionDescriptor();

    desc70.putInteger(stringIDToTypeID('seconds'), Seconds);

    desc70.putInteger(stringIDToTypeID('frame'), Frame);

    desc70.putDouble(stringIDToTypeID('frameRate'), frameRate);

    desc69.putObject(charIDToTypeID('T   '), stringIDToTypeID('timecode'), desc70);

    executeAction(charIDToTypeID('setd'), desc69, DialogModes.NO);

};

unction getCurrentFrame() {

    try {

        var ref = new ActionReference();

        ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('currentFrame'));

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

        var desc = new ActionDescriptor();

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

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

        return TC.getInteger(stringIDToTypeID('currentFrame'));

    } catch (e) { return null; }

};

function getTimelineLength() {

    var ref = new ActionReference();

    ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('duration'));

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

    var desc = new ActionDescriptor();

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

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

    TC = TC.getObjectValue(stringIDToTypeID('duration'));

    var M = 0;

    try { M = TC.getInteger(stringIDToTypeID('minutes')); } catch (e) { }

    var S = 0;

    try { S = TC.getInteger(stringIDToTypeID('seconds')); } catch (e) { }

    var F = TC.getInteger(stringIDToTypeID('frame'));

    var FR = TC.getInteger(stringIDToTypeID('frameRate'));

    var A = new Array();

    A.push([, , , [FR]]);

    return A;

}

var timeLineLenth = getTimelineLength();

var doc = activeDocument;

for (var i = 0; i <= timeLineLenth[0][1]; i++) {

    for (var j = 0; j < timeLineLenth[0][3]; j++) {

        gotoFrame(i, j, 30);

        var a = getCurrentFrame();

    }

}

This topic has been closed for replies.
Correct answer r-bin

I do not use animation at all, but maybe the following functions will be useful, i hope

function next_key_frame()

    {

    var d1 = new ActionDescriptor();

    var d2 = new ActionDescriptor();

    d2.putEnumerated( stringIDToTypeID( "trackID" ), stringIDToTypeID( "stdTrackID" ), stringIDToTypeID( "sheetPositionTrack" ) );

    d1.putObject( stringIDToTypeID( "trackID" ), stringIDToTypeID( "animationTrack" ), d2 );

    executeAction( stringIDToTypeID( "nextKeyframe" ), d1, DialogModes.NO );

    }

function prev_key_frame()

    {

    var d1 = new ActionDescriptor();

    var d2 = new ActionDescriptor();

    d2.putEnumerated( stringIDToTypeID( "trackID" ), stringIDToTypeID( "stdTrackID" ), stringIDToTypeID( "sheetPositionTrack" ) );

    d1.putObject( stringIDToTypeID( "trackID" ), stringIDToTypeID( "animationTrack" ), d2 );

    executeAction( stringIDToTypeID( "previousKeyframe" ), d1, DialogModes.NO );

    }

2 replies

Jarda Bereza
Inspiring
November 15, 2017

I tried to brute force on Action Manager code above with 5000+ stringIDs properties and this is only I can get.

documentTimelineSettings{ 

   "_obj":"object",

   "duration":{ 

      "_obj":"timecode",

      "frame":0.0,

      "frameRate":30.0,

      "seconds":5.0

   },

   "frameRate":30.0

}

duration{ 

   "_obj":"object",

   "duration":{ 

      "_obj":"timecode",

      "frame":0.0,

      "frameRate":30.0,

      "seconds":5.0

   }

}

enabled{ 

   "_obj":"object",

   "enabled":true

}

frameRate{ 

   "_obj":"object",

   "frameRate":30.0

}

time{ 

   "_obj":"object",

   "time":{ 

      "_obj":"timecode",

      "frame":2.0,

      "frameRate":30.0,

      "seconds":1.0

   }

}

workInTime{ 

   "_obj":"object",

   "workInTime":{ 

      "_obj":"timecode",

      "frame":0.0,

      "frameRate":30.0,

      "seconds":0.0

   }

}

workOutTime{ 

   "_obj":"object",

   "workOutTime":{ 

      "_obj":"timecode",

      "frame":0.0,

      "frameRate":30.0,

      "seconds":5.0

   }

Legend
November 15, 2017

And I found that

class "timeline" has properties:

time [ActionDescriptor]

currentFrame  INTEGERTYPE

documentTimelineSettings [ActionDescriptor] 

duration [ActionDescriptor]

enabled  BOOLEANTYPE

frameCount  INTEGERTYPE

frameRate  DOUBLETYPE

hasMotion  BOOLEANTYPE

workInTime [ActionDescriptor]

workOutTime [ActionDescriptor]

class "animationFrameClass" has properties:

animationFrameDelay  DOUBLETYPE

animationFrameReplace  ENUMERATEDTYPE animationFrameReplaceType.animationFrameReplaceAutoDispose

class "animationClass" has properties:

animationLoopCount INTEGERTYPE

currentFrame  INTEGERTYPE

enabled  BOOLEANTYPE

frameCount  INTEGERTYPE

)

r-binCorrect answer
Legend
October 31, 2017

I do not use animation at all, but maybe the following functions will be useful, i hope

function next_key_frame()

    {

    var d1 = new ActionDescriptor();

    var d2 = new ActionDescriptor();

    d2.putEnumerated( stringIDToTypeID( "trackID" ), stringIDToTypeID( "stdTrackID" ), stringIDToTypeID( "sheetPositionTrack" ) );

    d1.putObject( stringIDToTypeID( "trackID" ), stringIDToTypeID( "animationTrack" ), d2 );

    executeAction( stringIDToTypeID( "nextKeyframe" ), d1, DialogModes.NO );

    }

function prev_key_frame()

    {

    var d1 = new ActionDescriptor();

    var d2 = new ActionDescriptor();

    d2.putEnumerated( stringIDToTypeID( "trackID" ), stringIDToTypeID( "stdTrackID" ), stringIDToTypeID( "sheetPositionTrack" ) );

    d1.putObject( stringIDToTypeID( "trackID" ), stringIDToTypeID( "animationTrack" ), d2 );

    executeAction( stringIDToTypeID( "previousKeyframe" ), d1, DialogModes.NO );

    }

salithan73779666
Participating Frequently
October 31, 2017

Thanks a lot r-bin