Skip to main content
henryjeff
Participant
April 3, 2017
Question

Photoshop not visually updating while script is running?

  • April 3, 2017
  • 2 replies
  • 793 views

I wrote a script that SHOULD loop through every frame in my timeline as if it was playing the timeline, however Photoshop doesn't update when I move from frame to frame. I know its going to the frame but almost in the background. I'm wondering why it doesn't just visually show me each frame in my animation. Here is my script now and my play Timeline function is what isn't working. Feel free to try it out to see what I mean.

var doc = app.activeDocument;

var frameCount = getFrameCount();

playTimeline();

function playTimeline() {

    frameCount = getFrameCount();

    firstFrame();

    for(var i = 1; i < frameCount;i++){

        goToFrame(i);

        $.sleep(getDelay(i) * 1000);

    }

}

function getDelay (frame) {

    var ref = new ActionReference();

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

    ref.putIndex(stringIDToTypeID('animationFrameClass'), frame);

    var desc = new ActionDescriptor();

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

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

    return T.getDouble(stringIDToTypeID('animationFrameDelay'));

}

function getFrameCount() {

    var count = 1;

    while (goToFrame(count) != false) {

        count++;

    }

    return count - 1;

}

function goToFrame(frame) {

    try {

        var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putIndex(stringIDToTypeID("animationFrameClass"), frame);

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

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

        return true;

    } catch (e) {}

    return false;

}

function firstFrame(){

    var desc = new ActionDescriptor();

    var ref = new ActionReference();

    ref.putEnumerated(stringIDToTypeID("animationFrameClass"), charIDToTypeID("Ordn"), charIDToTypeID("Frst"));

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

    executeAction(stringIDToTypeID("animationFrameActivate"), desc, DialogModes.NO );

}

This topic has been closed for replies.

2 replies

Chuck Uebele
Community Expert
Community Expert
April 5, 2017

I don't know if this will work, but you can try to set the script to step mode and back to accelerate mode with these two functions:

//function to refresh screen after each step

function setActionToStep(){

    var idsetd = charIDToTypeID( "setd" );

        var desc1 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref1 = new ActionReference();

            var idPrpr = charIDToTypeID( "Prpr" );

            var idPbkO = charIDToTypeID( "PbkO" );

            ref1.putProperty( idPrpr, idPbkO );

            var idcapp = charIDToTypeID( "capp" );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref1.putEnumerated( idcapp, idOrdn, idTrgt );

        desc1.putReference( idnull, ref1 );

        var idT = charIDToTypeID( "T   " );

            var desc2 = new ActionDescriptor();

            var idperformance = stringIDToTypeID( "performance" );

            var idperformance = stringIDToTypeID( "performance" );

            var idstepByStep = stringIDToTypeID( "stepByStep" );

            desc2.putEnumerated( idperformance, idperformance, idstepByStep );

        var idPbkO = charIDToTypeID( "PbkO" );

        desc1.putObject( idT, idPbkO, desc2 );

    executeAction( idsetd, desc1, DialogModes.NO );

}//end function

// function to return action to accelerated mode - no refresh of screen for each step.=======================================================

function setActionToAcc(){

    var idsetd = charIDToTypeID( "setd" );

        var desc3 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref2 = new ActionReference();

            var idPrpr = charIDToTypeID( "Prpr" );

            var idPbkO = charIDToTypeID( "PbkO" );

            ref2.putProperty( idPrpr, idPbkO );

            var idcapp = charIDToTypeID( "capp" );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref2.putEnumerated( idcapp, idOrdn, idTrgt );

        desc3.putReference( idnull, ref2 );

        var idT = charIDToTypeID( "T   " );

            var desc4 = new ActionDescriptor();

            var idperformance = stringIDToTypeID( "performance" );

            var idperformance = stringIDToTypeID( "performance" );

            var idaccelerated = stringIDToTypeID( "accelerated" );

            desc4.putEnumerated( idperformance, idperformance, idaccelerated );

        var idPbkO = charIDToTypeID( "PbkO" );

        desc3.putObject( idT, idPbkO, desc4 );

    executeAction( idsetd, desc3, DialogModes.NO );

}//end function

JJMack
Community Expert
Community Expert
April 3, 2017

Perhaps if you replace the sleep with an application refresh you would see each frame the rate may be very slow. Replace your sleep with statement with app.refresh();  You may want to check if the scritlistener records any code when you use the timeline play button and use its play feature. Position to frame then use play. Play may not be record-able though.

JJMack
henryjeff
henryjeffAuthor
Participant
April 3, 2017

Yeah so this works now with app.refresh() but as you said its slow and the delays are thrown off as I want them to be at least 0.1 sec of delay. Is there no way you can update the app without it taking so long? (Also the play button in the timeline is not record-able.) Thanks!

JJMack
Community Expert
Community Expert
April 3, 2017

I think to only way you will be able to do want you want to see is to save out an animated gif or mp4 and view it in a html panel like Save for web preview in browser.

JJMack