I use calculations in my plugin and have my own function for it, it creates a newChannel and applies calculations into this new channel, returning the new channel name which normally is “Alpha 1”. I only use two Alphas so that’s why I have it hard coded, but you can change it at your own necessity.
Mind that I have the “if else” statement because doing caldulations with RGB channels is a different batchplay command than doing calculations with custom channels.
async function doCalculations(a, b, blend) {
try {
console.log(a);
if (a == "Alpha 1" || a == "Alpha 2") {
await batchPlay([
{
"_obj": "make",
"new": {
"_class": "channel"
},
"using": {
"_obj": "calculation",
"to": {
"_ref": "channel",
"_name": a
},
"calculation": {
"_enum": "calculationType",
"_value": blend
},
"source2": {
"_ref": "channel",
"_enum": "channel",
"_value": b
}
},
"_isCommand": true
}
], {});
} else {
await batchPlay([
{
"_obj": "make",
"new": {
"_class": "channel"
},
"using": {
"_obj": "calculation",
"to": {
"_ref": "channel",
"_enum": "channel",
"_value": a
},
"calculation": {
"_enum": "calculationType",
"_value": blend
},
"source2": {
"_ref": "channel",
"_enum": "channel",
"_value": b
}
},
"_isCommand": true
}
], {});
}
const channel = app.activeDocument.channels[app.activeDocument.channels.length - 1].name;
return channel;
} catch (e) {
console.log(e);
}
}
The function takes three arguments, the channelA, channelB and the blendingMode. This function also returns the name of the new channel that was created with the calculations on it.
Hope it is helpful for you.