Photoshop: get current video timeline frame


#1

Hey guys!

I’m working on a thingy that involves the Photoshop video timeline and I would like to programmatically query the current frame that the document is on. It’s proving more difficult than expected. If someone here is an expert at interpreting action references and descriptors, I’d appreciate tips.

My current approach is the following: I used the ScriptingListener to find out the command used to set the current frame. Then I try to guess how to construct the corresponding get action (with help of the following documents from the Photoshop SDK: /pluginsdk/documentation/html/_p_i_string_terminology_8h.html, /pluginsdk/documentation/html/_p_i_terminology_8h.html, SDK download available here https://www.adobe.com/devnet/photoshop/sdk.html).

Not much success yet. Not surprising as I’m pretty much shooting in the dark here. Figuring out how to set values is easy (do something in UI and record the API call) but I’m not aware of any easy method for deriving the getters. There’s no “get current frame number” button anywhere :laugh:

ScriptingListener + removing a couple of extra lines yielded the following working code (the recorded action sets frame rate and used seconds+frames as the unit, I do not need to set frame rate and use frame index as unit so I removed those lines and tested that the code still worked):

var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "time" ) );
ref1.putClass( stringIDToTypeID( "timeline" ) );
desc1.putReference( charIDToTypeID( "null" ), ref1 );
var desc2 = new ActionDescriptor();
desc2.putInteger( stringIDToTypeID( "frame" ), frameNumber );
desc1.putObject( charIDToTypeID( "T   " ), stringIDToTypeID( "timecode" ), desc2 );
executeAction( charIDToTypeID( "setd" ), desc1, DialogModes.NO );

This is how I’m trying to get the current frame from Photoshop at the moment:


var frameNumber;
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "time" ) );
ref1.putClass( stringIDToTypeID( "timeline" ) );
desc1.putReference( charIDToTypeID( "null" ), ref1 );
frameNumber = executeAction( charIDToTypeID( "getd" ), desc1, DialogModes.NO );
return frameNumber;

As you can tell, I’m confused. Ideally Adobe would have made things like this easily queryable from the document object tree, but AFAIK the timeline stuff needs to be accessed with the less-approachable executeAction calls. How to derive which properties and classes of which type I need to traverse to get to the info I’m after?


#2

Hello limeforce,

I know this is an old thread, but I was wondering did you menaged to workout this to work properly? I"m also trying to get the current frame number, and it seems there is steel no way of doing such a thing…

Thanks


#3

Hi Petar, actually I did. Been a while since I looked at this stuff but I found some code in my old files. The Photoshop API is needlessly cryptic, Adobe pls :unamused: I think I found the answer here: https://forums.adobe.com/message/4897995

function getFrameNumber(){
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;
}
};

Here’s another function you might find useful:

function goToFrame(frameNumber) {

try {
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "time" ) );
    ref1.putClass( stringIDToTypeID( "timeline" ) );
    desc1.putReference( charIDToTypeID( "null" ), ref1 );
    var desc2 = new ActionDescriptor();
    desc2.putInteger( stringIDToTypeID( "frame" ), frameNumber );
    desc1.putObject( charIDToTypeID( "T   " ), stringIDToTypeID( "timecode" ), desc2 );
    executeAction( charIDToTypeID( "setd" ), desc1, DialogModes.NO );

    return true;

} catch(e) {
    $.writeln(e);
}

return false;
}