Confused about suspend history usage

Thank you @Karmalakas it works now :smile:
here is the whole code for others who need it:


document.getElementById("btn").addEventListener("click", async function () {
  await ExecuteAsModal(doStuff);
});

async function doStuff(executionContext) {
  let hostControl = executionContext.hostControl;
  // let documentID = await getTargetDocument();

  let suspensionID = await hostControl.suspendHistory({
    documentID: app.activeDocument?.id,
    name: "New Layer",
  });

  // new SO
  await batchPlay(
    [
      {
        _obj: "make",
        _target: [{ _ref: "layer" }],
        using: { _obj: "layer", name: "New Layer" },
      },
      { _obj: "mergeVisible", duplicate: true },
      { _obj: "newPlacedLayer" },
    ],
    {}
  );

  await hostControl.resumeHistory(suspensionID);
}

1 Like