Skip to main content
Known Participant
September 28, 2019
Question

Getting Layer Duration in Photoshop Timeline

  • September 28, 2019
  • 4 replies
  • 1706 views

Hello,

I'm trying to write a script that changes the duration of a layer in the Photoshop timeline.

 

I haven't been able to find ANY information about the Timeline:

  • I have looked for scripting information about the Timeline in Photoshop Scripting Basics and Adobe Photoshop CC JavaScript Reference but found nothing.
  • I have also looked for Timeline objects in the Extendscript Toolkit Data Browser but found nothing.
  • I've looked at the ScriptingListenerJS.log and found an executeAction call for changing the Out Time, but nothing about the layer's duration:
    // =======================================================
    var idmoveOutTime = stringIDToTypeID( "moveOutTime" );
        var desc206 = new ActionDescriptor();
        var idtimeOffset = stringIDToTypeID( "timeOffset" );
            var desc207 = new ActionDescriptor();
            var idseconds = stringIDToTypeID( "seconds" );
            desc207.putInteger( idseconds, -4 );
            var idframe = stringIDToTypeID( "frame" );
            desc207.putInteger( idframe, -23 );
            var idframeRate = stringIDToTypeID( "frameRate" );
            desc207.putDouble( idframeRate, 24.000000 );
        var idtimecode = stringIDToTypeID( "timecode" );
        desc206.putObject( idtimeOffset, idtimecode, desc207 );
    executeAction( idmoveOutTime, desc206, DialogModes.NO );​

I'd need to know a layer's duration in order to know how much to reduce the OutTime in the Timeline.

 

Can anyone help me find documentation on how to script for the Photoshop Timeline?

 

Thank you!

4 replies

Participant
January 10, 2020

I wanted to decrease the outTime of all the layers to some value. What I ended up is decreasing the layer OutTime to zero and then increasing it back to where I want it to be. It appeared to work as an action. So I made the script.

 

Here is the final script to make all layers in th timeline be 1 second long:

 

var doc = app.activeDocument;

function ExecuteOnAllSets(item) {
    ExecuteOnAllLayersInSet(item, Action);
    
    var i = 0;
    while (i < item.layerSets.length) {
        ExecuteOnAllSets(item.layerSets[i]);
        i++; 
    }
}

function ExecuteOnAllLayersInSet(set, f) {
    var i = 0;
    while (i < set.artLayers.length) {
        SelectLayer(set.artLayers[i]);
        f();
        i++;
    }
}

function Action() {
    ChangeLayerTLLength(-90, 0);
    ChangeLayerTLLength(1, 0);
}

function ChangeLayerTLLength(seconds, frames) {
    var idmoveOutTime = stringIDToTypeID( "moveOutTime" );
        var desc8 = new ActionDescriptor();
        var idtimeOffset = stringIDToTypeID( "timeOffset" );
            var desc9 = new ActionDescriptor();
            var idseconds = stringIDToTypeID( "seconds" );
            desc9.putInteger( idseconds, seconds );
            var idframe = stringIDToTypeID( "frame" );
            desc9.putInteger( idframe, frames );
            var idframeRate = stringIDToTypeID( "frameRate" );
            desc9.putDouble( idframeRate, 30.000000 );
        var idtimecode = stringIDToTypeID( "timecode" );
        desc8.putObject( idtimeOffset, idtimecode, desc9 );
    executeAction( idmoveOutTime, desc8, DialogModes.NO );    
} 

function SelectLayer(layer) {
    doc.activeLayer = layer;
}

(function main() {
    ExecuteOnAllSets(doc);
})();

 

Kukurykus
Legend
September 29, 2019
Chuck Uebele
Community Expert
Community Expert
September 29, 2019

Someone who know how to modify AM code might be able to do it. I tried working with the timeline once and asked an Adobe engineer about it, and all he replied as, "It's black magic."

Mylenium
Legend
September 29, 2019

I don't think they are officially documented anywhere "for reasons".  The UI callbacks are probably everything you are ever going to get from this self-contained bubble.

 

Mylenium