Get selection bounds does not work with minVersion 23.0.0

When minVersion is 23.0.0. Below code to get selection bounds does not work.


const core = require("photoshop").core;
   await core.executeAsModal(() => {
   bounds =  getSelectionBounds(activeDoc._id);
   })

async function getSelectionBounds(documentId) {
   try {
      await core.executeAsModal(() => {
      const result = batchPlay(
         [
            {
               "_obj": "get",
               "_target": [
                  {
                     "_property": "selection"
                  },
                  {
                     "_ref": "document",
                     "_id": documentId
                  }
               ],
               "_options": {
                  "dialogOptions": "dontDisplay"
               }
            }
         ], {});
      })
      var x1 = result[0].selection.left._value;
      var y1 = result[0].selection.top._value;
      var x2 = result[0].selection.right._value;
      var y2 = result[0].selection.bottom._value;
      return [x1, y1, x2, y2];
   } catch (error) {
      return false;
   }
}

Can you please help ?

1 Like

Check what you get for result and I believe you will see the issue

P. S. Why do you double wrap in executeAsModal()?

I always get false value as a result.

I meant result variable, not bounds result
Iā€™m pretty sure you get a Promise here:

const result = batchPlay(<...>)

Thanks @Karmalakas I got result.