Skip to main content
Participating Frequently
November 2, 2017
Answered

Executing Sub-Action of Action in Photoshop via Script

  • November 2, 2017
  • 4 replies
  • 2402 views

Hello everyone!

I write script for animating of my work's process.

So, idea is simple:

I record my brush strokes with Actions. When work is done I execute script which calls these Actions and after each several brush strokes Photoshop exports numbered image for further video editing.

At the moment I found only app.doAction("Action", "Action Set") command for Adobe ExtendScript Toolkit which executes whole action at once without controlling of subactions.

Could you tell me, please, is there any command like app.doAction.doSubAction("SubAction", "Action", "Action Set") for executing suboperations of Action?

For example, I want to export state of the painting after every 10 brush strokes inside certain Action. I need script something like this:

var steps = 1000;

var j = 0;

var index = 0;

for (i=1; i < steps; i++)

{

     app.doAction.doSubAction(nextSubAction, "Action", "Action Set");

     j++;

     if (j == 9)

     {

          jpgFile = new File("d:/frame" + '0000'.substr(String(i).length) + index + ".jpg");

         saveOptions = new JPEGSaveOptions();

         saveOptions.embedColorProfile = true;

         saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

         saveOptions.matte = MatteType.NONE;

         saveOptions.quality = 12;

         app.activeDocument.saveAs(jpgFile, saveOptions, true, Extension.LOWERCASE);

         j = 0;

         index ++;

     }

}

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

Examples of using:

play_action("Set 1", "Action 1") // Perform the whole action

play_action("Set 1", "Action 1", 4, true) // Complete all from the beginning of the command number 4

play_action("Set 1", "Action 1", 5, false) // Will execute only command number 5

// cmd_number - the index of the command, ( starts from 1 )

function play_action(set, action, cmd_number, allow_continue)

    {

    try

        {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        if (typeof(cmd_number) == "number") r.putIndex( charIDToTypeID( "Cmnd" ), cmd_number );

        r.putName( charIDToTypeID( "Actn" ), action );

        r.putName( charIDToTypeID( "ASet" ), set );

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

        if (typeof(allow_continue) == "boolean") d.putBoolean( charIDToTypeID( "Cntn" ), allow_continue );

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

        }

    catch(e) { alert(e); }

    }

4 replies

natrev
Legend
December 1, 2017

Hi AzatKhafizov

Hope this link will Help...

Play Palette Action | Tonton Pixel

-yajiv

Participating Frequently
December 1, 2017

natrev, thank you for the script!

It is a little bit different from the thing that I needed, but in fact it's also useful for work.

r-binCorrect answer
Legend
November 29, 2017

Examples of using:

play_action("Set 1", "Action 1") // Perform the whole action

play_action("Set 1", "Action 1", 4, true) // Complete all from the beginning of the command number 4

play_action("Set 1", "Action 1", 5, false) // Will execute only command number 5

// cmd_number - the index of the command, ( starts from 1 )

function play_action(set, action, cmd_number, allow_continue)

    {

    try

        {

        var d = new ActionDescriptor();

        var r = new ActionReference();

        if (typeof(cmd_number) == "number") r.putIndex( charIDToTypeID( "Cmnd" ), cmd_number );

        r.putName( charIDToTypeID( "Actn" ), action );

        r.putName( charIDToTypeID( "ASet" ), set );

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

        if (typeof(allow_continue) == "boolean") d.putBoolean( charIDToTypeID( "Cntn" ), allow_continue );

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

        }

    catch(e) { alert(e); }

    }

Participating Frequently
December 1, 2017

r-bin, your answer was absolutely helpful!

Thank you very much!

Now I record process of creation of my paintings.

Here is result of using your script combined with my approach from initial post:

Chuck Uebele
Community Expert
Community Expert
November 28, 2017

I don't believe so. The best you can do is break down your actions into small steps, then reference them.

Akash Sharma
Legend
November 28, 2017

Moving to Photoshop Scripting

Participating Frequently
December 1, 2017

Akash Sharma, thank you for moving this thread in the right category!

In fact, it was the strong reason why r-bin could see the theme in the threads' list and could help with the solution.