Skip to main content
Participant
January 18, 2024
Question

Group of action within an UNDO command in UXP plugins

  • January 18, 2024
  • 1 reply
  • 566 views

Hi all,

 

I would like to group together more than 2 actions for them to be part of the same UNDO command.

I have seem some options (begin/endUndoGroup and suspendHistory) but it seems that none of them are available for UXP plugins.

I have read some comments including a proposal to use batchPlay for this.

Is this the unique option for this problem?

Thank you in advance!

 

 

  

1 reply

Davide_Barranca12040269
Legend
January 19, 2024

When you say "2 actions", do you mean two separate functions or actual items from the Actions palette?

Davide Barranca - PS developer and authorwww.ps-scripting.com
Participant
January 19, 2024

I mean two actions, as for instance:

  • call to "insertImageAsLayer" and then,
  • call to"putSelection"
Davide_Barranca12040269
Legend
January 19, 2024

> when you say "2 actions"...
> I mean two actions...

 

LOL

If you want to run two Actions (capital A):

 

const { app } = require("photoshop");
app.activeDocument.suspendHistory(async (context) => {
  await app.actionTree
    .find(({ name }) => name === "Set 1")
    .actions.find(({ name }) => name === "Action 1")
    .play();

  await app.actionTree
    .find(({ name }) => name === "Set 1")
    .actions.find(({ name }) => name === "Action 2")
    .play();

  // Etc.
}, "Running a bunch of Actions");

 

If you want to run multiple ActionJSON descriptors, then BatchPlay supports the array notation:

 

await app.activeDocument.suspendHistory(async () => {
  await batchPlay(
    [
      { /* ... */ },
      { /* ... */ },
    ],
    {}
  );
}, "Custom history string here ");

 

HTH

 

Davide Barranca - PS developer and authorwww.ps-scripting.com