How to get a guide after making it with batchplay?

Hi there, I’m working on transitioning my tooling from CEP to UXP. In one of my tool’s flow in CEP, I added guides, let the user move them, and then later got the position of them.

I can make a guide using batch play, but it looks like I can’t get the guide without the guide’s ID, which isn’t shown during the batch play make.

function CreateGuide( documentID, position, orientation ) {

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

    const result = batchPlay(
        [
            {
                "_obj": "make",
                "new": {
                    "_obj": "good",

                    "position": {
                        "_unit": "pixelsUnit",
                        "_value": position
                    },
                    "orientation": {
                        "_enum": "orientation",
                        "_value": orientation
                    },
                    "kind": {
                        "_enum": "kind",
                        "_value": "document"
                    },
                    "_target": [
                        {
                            "_ref": "document",
                            "_id": documentID
                        },
                        {
                            "_ref": "good",
                            "_index": 1
                        }
                    ]
                },

                "_target": [
                    {
                        "_ref": "good"
                    }
                ],
                "guideTarget": {
                    "_enum": "guideTarget",
                    "_value": "guideTargetCanvas"
                },
                "_isCommand": true,
                "_options": {
                    "dialogOptions": "dontDisplay"
                }
            }
        ], {
        "synchronousExecution": false,
        "modalBehavior": "fail"
    } );
    console.log( result );
}

Alchemist shows this way to get a guide. In which you have to provide the ID.

async function GetGuide( documentId, Id ) {
    const batchPlay = require( "photoshop" ).action.batchPlay;
    const result = await batchPlay(
        [
            {
                "_obj": "get",
                "_target": [
                    {
                        "_ref": "guide",
                        "_id": Id
                    },
                    {
                        "_ref": "document",
                        "_id": documentId
                    }
                ],
                "_options": {
                    "dialogOptions": "dontDisplay"
                }
            }
        ], {
        "synchronousExecution": false,
        "modalBehavior": "fail"
    } );
    return result;
}

I’ve only recently been deep diving into batchplay, is it possible to set the “_id” during the make action? Or am I completely off the mark and should I be doing something else?

Thank you for the help!

you could try index:

async function CreateGuide( documentID, position, orientation ) {

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

  const result =await  batchPlay(

      [

          {

              "_obj": "make",

              "new": {

                  "_obj": "good",

                  "position": {

                      "_unit": "pixelsUnit",

                      "_value": position

                  },

                  "orientation": {

                      "_enum": "orientation",

                      "_value": orientation

                  },

                  "kind": {

                      "_enum": "kind",

                      "_value": "document"

                  },

                  "_target": [

                      {

                          "_ref": "document",

                          "_id": documentID

                      },

                      {

                          "_ref": "good",

                          "_index": 1

                      }

                  ]

              },

              "_target": [

                  {

                      "_ref": "good"

                  }

              ],

              "guideTarget": {

                  "_enum": "guideTarget",

                  "_value": "guideTargetCanvas"

              },

              "_isCommand": true,

              "_options": {

                  "dialogOptions": "dontDisplay"

              }

          }

      ], {

      "synchronousExecution": false,

      "modalBehavior": "fail"

  } )

  indx= (result[0].new._target[1]._index)

  return indx 

  }

async function GetGuide( documentId, index ) {

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

  const result = await batchPlay(

      [

          {

              "_obj": "get",

              "_target": [

                  {

                      "_ref": "guide",

                      "_index": index

                  },

                  {

                      "_ref": "document",

                      "_id": documentId

                  }

              ],

              "_options": {

                  "dialogOptions": "dontDisplay"

              }

          }

      ], {

      "synchronousExecution": false,

      "modalBehavior": "fail"

  } );

  return result;

}

//when you execute the function get the index

 CreateGuide( documentID, position, orientation).then(function(result) {index=(result);
    
})

Index works! Thank you so much