Get PS Document Slices

Is there a way to get the current slices in a PS document? Trying the following BatchPlay throws a The command “Get” is not currently available error.

image

batchPlay(
        [
          {
            _obj: "get",
            _target: [
              {
                _ref: "slice",
                _enum: "ordinal",
                _value: "allEnum",
              },
            ],
            _options: {
              dialogOptions: "dontDisplay",
            },
          },
        ],
        {
          synchronousExecution: false,
          modalBehavior: "fail",
        }
      )

Turns out getting the slices from the BatchPlay document solves this for now:

  const ps = require("photoshop");
  const batchPlay = ps.action.batchPlay;

  const getSlices = (doc) => {
    return new Promise((resolve, reject) => {
      ps.core.executeAsModal(() => {
        batchPlay(
          [
            {
              _obj: "get",
              _target: [
                {
                  _ref: "document",
                  _id: doc._id,
                },
              ],
              _options: {
                dialogOptions: "dontDisplay",
              },
            },
          ],
          {
            synchronousExecution: false,
            modalBehavior: "fail",
          }
        ).then((res) => {
          resolve(res[0].slices);
        });
      });
    });
  };

  await getSlices(ps.app.activeDocument);
1 Like