Before asking this, I checked here and here to get an idea of how to construct things. It seems that, for a layer transformation to work via batchPlay(), I need to have the active layer selected (which I do), and I need to specify the target layer ID in the action descriptor. So I cast the action descriptor as a function return value:
function eventTransformSelection(id, horiz = 0, vert = 0, scale = 100) {
return {
"_obj": "transform",
"_target": [
{
_ref: "layer",
_id: id
}
],
"freeTransformCenterState": {
"_enum": "quadCenterState",
"_value": "QCSAverage"
},
"offset": {
"_obj": "offset",
"horizontal": {
"_unit": "pixelsUnit",
"_value": horiz
},
"vertical": {
"_unit": "pixelsUnit",
"_value": vert
}
},
"width": {
"_unit": "percentUnit",
"_value": scale
},
"height": {
"_unit": "percentUnit",
"_value": scale
},
"replaceLayer": {
"_obj": "transform",
"from": {
"_ref": "layer",
"_id": id
},
"to": {
"_ref": "layer",
"_id": id
}
}
};
}
I have a button which should take input values and populate that action descriptor:
document.getElementById("btn-transform-selection").addEventListener('click', async function () {
let id = app.activeDocument.activeLayers[0].id;
let batchCommands = [eventTransformSelection(id, 0, 0, 200)]; // (id, xDisp, yDisp, scalePercent)
async function resize() {
return await batchPlay(batchCommands, {});
}
}
try {
return await executeAsModal(resize, { commandName: "Transform Selection" });
} catch (e) {
console.error(e);
}
});
This currently returns no errors. I’ve stuck console logs everywhere on and off to try to figure out where it fails, but I’ve been unable to get this to spit out an error. It should scale the layer by 200%, but nothing happens. It’s gotta be something obvious.