I am trying to learn batchplay by building single step functions, such as duplicate layer, or create a new fill layer. But one of them doesn’t work and I can’t figure out why.
I have gotten duplicate layer to work after grokking some out of date documentation, but Create Fill Layer still fails with no error or debug messages. In addition, there appears to be a spelling error in the command, which makes me even more lost.
Process:
- use Plugin> Development > Record Action Command
- press the new adjustment layer button in the Layers panel.
- select new fill layer.
- pick a color.
- layer is created, I end the Action Recording.
I then plug this into a function, the same way I did with duplicate layer.
Please make note that the “green” variable was spelled “grain” by Photoshop itself. I have tried both green and grain
function createFillLayer(r=255.0, g=255.0, b=255.0){
async function _createFillLayer(r, g, b){
result = await batchPlay(
[
{"_obj":"make","_target":[{"_ref":"contentLayer"}],"using":{"_obj":"contentLayer","type":{"_obj":"solidColorLayer","color":{"_obj":"RGBColor","blue":b,"grain":g,"red":r}}}}
], {}
)
//console.warn(result)
}
utils.executeAsModalHelper(_createFillLayer(r, g, b), "fill layer")
return
}
in Utils.js:
async function executeAsModalHelper (
targetFunction,
commandName="myCommand",
suspendHistory = true
) {
/*handles errors in execute as modal for you.
targetFunction : the func to excecute. It must have the following signature:
async function targetFunction(executionContext, descriptor)
options : 1. commandName (optional): A string describing the command.
This string is shown in the progress bar UI.
2. suspendHistory (optional): Should the entire targetFunction be 1 history call? This needs to be re
3. interactive (optional): A boolean to toggle interactive mode.
*/
try {
await executeAsModal(targetFunction, { commandName: commandName })
} catch (e) {
if (e.number == 9) {
showAlert(
'executeAsModal was rejected (some other plugin is currently inside the modal scope'
)
console.error(
'executeAsModal was rejected (some other plugin is currently inside the modal scope'
)
} else {
// This case is hit if the targetFunction throws an exception
console.error(str(targetFunction) + ' function failed!')
}
}
}
However, this function works fine, and I cant figure what the difference is.
function duplicateLayer(layerToCopy="Color Fill 2", layerIDToCopy=1079, newLayerID=1080){
async function _duplicateLayer(layerToCopy="Color Fill 2", layerIDToCopy=1079, newLayerID=1080){
result = await batchPlay(
[
{"_obj":"select","_target":[{"_name":"Color Fill 2","_ref":"layer"}],"layerID":[1079],"makeVisible":false},
{"ID":[1080],"_obj":"duplicate","_target":[{"_enum":"ordinal","_ref":"layer"}],"version":5}
], {}
)
}
utils.executeAsModalHelper(_duplicateLayer, "DuplicateLayer")
}