• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Timer counter for a custom animation timeline

New Here ,
Oct 21, 2017 Oct 21, 2017

Copy link to clipboard

Copied

So I'm trying to playback the layers, to shuffle trough them in specific intervals of time - therefore creating something like a "Play" functionality that we have in the timeline panel. My idea was to use something like this:

for (i=0; i<animationLength; i++) {

        $.sleep (1000/framerate);

        shuffleLayer();

        }

The problem with this is that the phothoshop hangs while the script is not fully executed, so I cannot see the changes on every loop iteration. So I've tried introducing the app.refresh() function:

for (i=0; i<animationLength; i++) {

        $.sleep (1000/framerate);

        shuffleLayer();

        app.refresh();

        }

And aldough, this works, the refresh function is very slow. It takes around a full second to execute one for loop iteration. It's not really usable for thing like this. I also tried using 'while loop' with date measurement, but I still have the same problem. Does anyone know is there a better approach for something like this?

TOPICS
Actions and scripting

Views

711

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Oct 21, 2017 Oct 21, 2017

Try to use such function instead of app.refresh()

function clear_guides()

    {

    try {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putEnumerated( charIDToTypeID( "Gd  " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al  " ) );

        d.putReference( charIDToTypeID( "null" ), r );

        executeAction( charIDToTypeID( "Dlt " ), d, DialogModes.NO );

        d = null;

        r = null;

        }

    catch (e) { alert(e); throw(e); }

    }

On CS6 it very fast redra

...

Votes

Translate

Translate
Adobe
People's Champ ,
Oct 21, 2017 Oct 21, 2017

Copy link to clipboard

Copied

Try to set manualy in actions panel or via srcipt "PlaybackOptions performance" to stepByStep. And don't use refresh().

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 21, 2017 Oct 21, 2017

Copy link to clipboard

Copied

Unfortunately, this will not work, because the canvas does not get to upade itself if the actions are firing rapidly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 21, 2017 Oct 21, 2017

Copy link to clipboard

Copied

Try to use such function instead of app.refresh()

function clear_guides()

    {

    try {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putEnumerated( charIDToTypeID( "Gd  " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al  " ) );

        d.putReference( charIDToTypeID( "null" ), r );

        executeAction( charIDToTypeID( "Dlt " ), d, DialogModes.NO );

        d = null;

        r = null;

        }

    catch (e) { alert(e); throw(e); }

    }

On CS6 it very fast redraw current doc (when in step-by-step mode))

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 21, 2017 Oct 21, 2017

Copy link to clipboard

Copied

Ok, I see what you did there...

I wish it could go even faster but it does the job. Idealy I need it to shuffle up to 24 layers per second, but I realise now that would be pretty havy for photoshop to deal with this way. Also, 'clear guides action' is messing up my doc history...

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 21, 2017 Oct 21, 2017

Copy link to clipboard

Copied

You can try my vertion of redraw_doc() function. May be faster )

////////////////////////////////////////////////////////////////////////////////////////////

var _redraw_doc_id;

////////////////////////////////////////////////////////////////////////////////////////////

function redraw_doc()

    {

    try {

        if (_redraw_doc_id != app.activeDocument.id)

            {

            _redraw_doc_id = app.activeDocument.id;

            showAll();

            }

        step_by_step();

        if (!app.activeDocument.guides.length)

            {

            clear_guides();

            }

        else

            {

            show_guides();

            }

        accelerated();

        }

    catch (e) { accelerated(); refresh(); }

    }

////////////////////////////////////////////////////////////////////////////////////////////

function menu(type_str, force_str, dlg, err_ctrl)

    {

    try {

        var id = (type_str.length==4) ? charIDToTypeID(type_str) : stringIDToTypeID(type_str);

        if (force_str == true) id = stringIDToTypeID(type_str);

        var r = new ActionReference();

        var d  = new ActionDescriptor();

        var ret = true;

       

        try {

            r.putEnumerated( charIDToTypeID( "Mn  " ), charIDToTypeID( "MnIt" ), id );

            d.putReference( charIDToTypeID( "null" ), r );

            executeAction( charIDToTypeID( "slct" ), d, dlg==true?DialogModes.ALL:DialogModes.NO );

            }

        catch(e) { if (err_ctrl) alert(e); ret = false; }

        r = null;

        d = null;

        return ret;

        }

    catch (e) { alert(e); throw(e); }

    }

////////////////////////////////////////////////////////////////////////////////////////////

function showAll()

    {

    try {

        menu("showAll");

        menu("TgGr");

        menu("toggleLayerEdges");

        menu("toggleSlices");

        }

    catch (e) { alert(e); throw(e); }

    }

////////////////////////////////////////////////////////////////////////////////////////////

function clear_guides()

    {

    try {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putEnumerated( charIDToTypeID( "Gd  " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al  " ) );

        d.putReference( charIDToTypeID( "null" ), r );

        executeAction( charIDToTypeID( "Dlt " ), d, DialogModes.NO );

        d = null;

        r = null;

        }

    catch (e) { alert(e); throw(e); }

    }

////////////////////////////////////////////////////////////////////////////////////////////

function show_guides()

    {

    try {

        var d1 = new ActionDescriptor();

        var d2 = new ActionDescriptor();

        d2.putUnitDouble( charIDToTypeID( "Pstn" ), charIDToTypeID( "#Prc" ), 200 );

        d2.putEnumerated( charIDToTypeID( "Ornt" ), charIDToTypeID( "Ornt" ), charIDToTypeID( "Hrzn" ) );

        d1.putObject( charIDToTypeID( "Nw  " ), charIDToTypeID( "Gd  " ), d2 );

        executeAction( charIDToTypeID( "Mk  " ), d1, DialogModes.NO );

        app.activeDocument.guides[app.activeDocument.guides.length-1].remove();

        d1 = null;

        d2 = null;

        }

    catch (e) { alert(e); throw(e); }

    }

////////////////////////////////////////////////////////////////////////////////////////////

function accelerated()

    {

    try {

        var d1 = new ActionDescriptor();

        var d2 = new ActionDescriptor();

        var r1 = new ActionReference();

        r1.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( "PbkO" ) );

        r1.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

        d1.putReference( charIDToTypeID( "null" ), r1 );

        d2.putEnumerated( stringIDToTypeID( "performance" ), stringIDToTypeID( "performance" ), stringIDToTypeID( "accelerated" ) );

        d1.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "PbkO" ), d2 );

        executeAction( charIDToTypeID( "setd" ), d1, DialogModes.NO );

               

        r1 = null;

        d2 = null;

        d1 = null;

        }

    catch (e) { throw(e); }

    }

////////////////////////////////////////////////////////////////////////////////////////////

function step_by_step()

    {

    try {

        var d1 = new ActionDescriptor();

        var d2 = new ActionDescriptor();

        var r1 = new ActionReference();

        r1.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( "PbkO" ) );

        r1.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

        d1.putReference( charIDToTypeID( "null" ), r1 );

        d2.putEnumerated( stringIDToTypeID( "performance" ), stringIDToTypeID( "performance" ), stringIDToTypeID( "stepByStep" ) );

        d1.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "PbkO" ), d2 );

        executeAction( charIDToTypeID( "setd" ), d1, DialogModes.NO );

               

        r1 = null;

        d2 = null;

        d1 = null;

        }

    catch (e) { throw(e); }

    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 21, 2017 Oct 21, 2017

Copy link to clipboard

Copied

LATEST

to preserve history use app.activeDocument.suspendHistory function.

app.activeDocument.suspendHistory("Redraw", "redraw_doc()");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines