'placedLayerReplaceContents' is not available

Hello,

I’m trying to replace a smart object’s content with another file via batchPlay.

My batchPlay command is:
[
{
_obj: "placedLayerReplaceContents",
_target: [
{
_ref: "layer",
_id: sourceLayerId }]
null: {
_path: params.ImageToken
},
_isCommand: true
}
]

Where params.ImageToken is a valid file token, and sourceLayerId is the ID of the layer that I wish to replace.

When I run this, I receive the following error message:

[{“_obj”:“error”,“message”:“my-extension: The command “Replace Contents” is not currently available.”,“result”:-25920}]

I’ve confirmed that the sourceLayerId is correct, and the token is valid.

If I remove _target and ensure that the target layer is selected within Photoshop when the action is run, it works, but that is not a workable solution in my case, and I need the extension to be able to dynamically target the correct layer without user intervention.

What am I doing wrong here?

Just guessing here, but some things require the layer to be selected. Have you tried making sure that layer is slected and is the only selected layer with uxp before running your replace?

1 Like