'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

Late to the party, but I found in the old javascript .jsx land that most (maybe all?) smart object manipulations required that the layer be the only active selected layer.

I worked around it by making an active selection save state, doing the smart object manipulations, then restoring the active selections from before.

It is sad we still have to deal with these low-level undocumented quirks. PS DOM handle this automatically, but its API has nothing even close to related to Smart Objects.

“Fun” fact. If your layer is hidden by layer filter you cannot select it and it will fail even in PS DOM and there is no easy way to tell whether filter is on/off.

2 Likes