How can I edit Text Layer contents with batchplay by using Layer ID and Document ID?

Hi!
I’m trying to edit the contents of some text layers.
Since the working env. should open multiple documents, I have to access the target with documentID and layerID.

So, I tried this…which is crushing… :roll_eyes:

const batchPlay = await require("photoshop").action.batchPlay;
await batchPlay(
        [{
            "_obj": "set",
            "_target": [
                {
                    "_ref": "textLayer",
                    "_id": parseInt(layerID)
                }
            ],
            "documentID": parseInt(docID),
            "to": {
                "_obj": "textLayer",
                "textKey": transString
                },
            "_isCommand": true,
            "_options": {
                "dialogOptions": "dontDisplay"
            }
        }], 
        {
            "synchronousExecution": true,
        });

and this…that is also crushing… :face_vomiting:

    const batchPlay = await require("photoshop").action.batchPlay;
    await batchPlay(
        [{
            "_obj": "set",
			"_target": [
				{
					"_ref": "textLayer",
					"_id": parseInt(layerID)
				},
                {
                    "_ref": "document",
                    "_id": parseInt(docID)
                }    
			],
			"to": {
				"_obj": "textLayer",
				"textKey": transString
                },
            "_isCommand": true,
            "_options": {
                "dialogOptions": "dontDisplay"
            }
        }], {
            "synchronousExecution": true,
        });
}

I can’t access a certain layer of a document by using ID…
how can I fix this :frowning:

do “select” and then “set” in synchronous batchPlay

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

const result = await batchPlay(
[
   {
      "_obj": "select",
      "_target": [
         {
            "_ref": "layer",
            "_id": layerid_here
         }
      ],
      "_isCommand": true,
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }, {
      "_obj": "set",
      "_target": [
         {
            "_ref": "textLayer",
            "_enum": "ordinal",
            "_value": "targetEnum"
         }
      ],
      "to": {
         "_obj": "textLayer",
         "textKey": your_text_here,

         // ...
         /// ...

],{
   "synchronousExecution": true,
   "modalBehavior": "fail"
});
1 Like

But this does not select the document. And there’s no need to select layer if you know the ID

1 Like

but the “set” command doesnt have layer id in it… my work around is to select the document, then the the text layer

1 Like

What do you mean by that? You can pass layer ID as usual:

            "_target": [
                {
                    "_ref": "textLayer",
                    "_id": parseInt(layerID)
                }
            ],

Which part of your code selects the document? All I see is selecting the layer:

      "_obj": "select",
      "_target": [
         {
            "_ref": "layer",
            "_id": layerid_here
         }
      ],

And then using that selected layer

      "_target": [
         {
            "_ref": "textLayer",
            "_enum": "ordinal",
            "_value": "targetEnum"
         }
      ],
2 Likes

omg u r right ahaha



const result = await batchPlay(
        [{
            "_obj": "select",
            "_target": [
                {
                    "_ref": "document",
                    "_id": documentID
                }
            ],
            "_isCommand": true
            
        },{
            "_obj": "set",
            "_target": [
                {
                    "_ref": "textLayer",
                    "_id": layerID
                }
            ],
            "to": {
                "_obj": "textLayer",
                "textKey": "AWESOME STRING HERE"
                },
            "_isCommand": true,
            "_options": {
                "dialogOptions": "dontDisplay"
            }
        }], 
        {
            "synchronousExecution": true,
        });
console.log(result);

2 Likes

@flipnism, @Karmalakas
Thank you for replies!
chaining “select” and “set” totally worked!

Send you many thanks!!!