How Would You Deal With Suspend History On This Scenario

I have a button which when pressed Duplicates the document and then performs a series of recorded actions.

Issue:
After the document is duplicated, all the action steps are shown in the history panel.
Im guessing this is because its seen as a fresh document and not the one from which the button was pressed.

Is there a way to suspend history on the duplicated document

I suppose two calls to executeAsModal(). In first you duplicate document and get new doc ID. In second you use that new ID and suspend history there for all the actions

Do you have any examples please.

It seems you can have nested modal scopes, so probably in your first modal, when you get new doc ID, you could call another.

But now I think you could just initiate another history suspension state :thinking:

Something like:

photoshop.core.executeAsModal(async (executionContext) => {
        const hostControl = executionContext.hostControl

        const suspensionIDDuplication = await hostControl.suspendHistory({
            historyStateInfo: {
                name: "History state name",
                target: [{
                    _ref: "document",
                    _id: photoshop.app.activeDocument.id,
                }]
            }
        })

        // Do duplication stuff and get ID

        await hostControl.resumeHistory(suspensionIDDuplication)

        const suspensionIDNewDoc = await hostControl.suspendHistory({
            historyStateInfo: {
                name: "New doc history state",
                target: [{
                    _ref: "document",
                    _id: newDocID,
                }]
            }
        })

        // Do stuff on new document

        await hostControl.resumeHistory(suspensionIDNewDoc )
    }, {commandName})

More examples in the docs here
Sorry, didn’t test it in practice myself

Edit: I see in the docs now suspendHistory() has a bit different signature:

    let suspensionID = await hostControl.suspendHistory({
        "documentID": documentID,
        "name": "Custom Command"
    });

Probably will have to revisit my own plugins

@Karmalakas Thanks for the information. I was not aware you could stack these in one single function.

I tried your first example and it does what I wanted. I will relook at the docs to see what has changed with regards the signature.

Thank you.