Hi, first thing to say I’m a noob. I love to automate my retouch workflows but my dev knowledge is close to zero.
I’ve built quite advanced CEP panel in the past but now I’m struggling with UXP and Batchplay.
I’m using Occultist and Alchemist to create batchplay script from PS action.
In case of some actions I’ve noticed that they will not work (I’m getting errors in PS) if I’ll not remove some square brackets [ ].
This is an example generated by Occultist that doesn’t work:
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
_obj: "make",
_target: [
{
_ref: "layer"
}
],
layerID: 117,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "make",
new: {
_class: "channel"
},
at: [
{
_ref: "channel",
_enum: "channel",
_value: "mask"
}
],
using: {
_enum: "userMaskEnabled",
_value: "revealAll"
},
_options: {
dialogOptions: "dontDisplay"
}
}
],{
synchronousExecution: false,
modalBehavior: "wait"
});
I’ve found out that if I’ll remove [ ] inside of _obj: it will work:
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
_obj: "make",
_target:
{
_ref: "layer"
}
,
layerID: 117,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "make",
new: {
_class: "channel"
},
at:
{
_ref: "channel",
_enum: "channel",
_value: "mask"
}
,
using: {
_enum: "userMaskEnabled",
_value: "revealAll"
},
_options: {
dialogOptions: "dontDisplay"
}
}
],{
synchronousExecution: false,
modalBehavior: "wait"
});
I have no idea why but it does.
This is how I execute the script:
async function test() {
// code generated by Ocultist / Alchemist
}
document.querySelector("#btntest").addEventListener("click", test)
Unfortunately this simple trick doesn’t work in case of some objects like _obj: “applyImageEvent”
I’m using them in Frequency separation actions, High Pass sharpening etc. It’s crucial for me to make it work in UXP panel.
This is the part of the code that doesn’t work because if I’ll remove [ ] I’m getting errors:
{
_obj: "applyImageEvent",
with: {
_obj: "calculation",
to: [
{
_ref: "channel",
_enum: "channel",
_value: "RGB"
},
{
_ref: "layer",
_name: "Frequency Separation LF"
}
],
calculation: {
_enum: "calculationType",
_value: "subtract"
},
scale: 2,
offset: 128
},
_options: {
dialogOptions: "dontDisplay"
}
}
And the full script I’m using for Frequency Separation:
async function fsgaussian() {
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
_obj: "make",
_target:
{
_ref: "layer"
}
,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "mergeVisible",
duplicate: true,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "set",
_target:
{
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
}
,
to: {
_obj: "layer",
name: "Frequency Separation LF"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "make",
_target:
{
_ref: "layer"
}
,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "mergeVisible",
duplicate: true,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "set",
_target:
{
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
}
,
to: {
_obj: "layer",
name: "Frequency Separation HF"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "set",
_target:
{
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
}
,
to: {
_obj: "layer",
opacity: {
_unit: "percentUnit",
_value: 0
},
layerEffects: {
_obj: "layerEffects",
scale: {
_unit: "percentUnit",
_value: 333.3333333333333
}
}
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "select",
_target:
{
_ref: "layer",
_enum: "ordinal",
_value: "backwardEnum"
}
,
makeVisible: false,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "gaussianBlur",
radius: {
_unit: "pixelsUnit",
_value: 4.5
},
_options: {
dialogOptions: "display"
}
},
{
_obj: "select",
_target:
{
_ref: "layer",
_enum: "ordinal",
_value: "forwardEnum"
}
,
makeVisible: false,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "applyImageEvent",
with: {
_obj: "calculation",
to: [
{
_ref: "channel",
_enum: "channel",
_value: "RGB"
},
{
_ref: "layer",
_name: "Frequency Separation LF"
}
],
calculation: {
_enum: "calculationType",
_value: "subtract"
},
scale: 2,
offset: 128
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "set",
_target:
{
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
}
,
to: {
_obj: "layer",
opacity: {
_unit: "percentUnit",
_value: 100
},
mode: {
_enum: "blendMode",
_value: "linearLight"
},
layerEffects: {
_obj: "layerEffects",
scale: {
_unit: "percentUnit",
_value: 333.3333333333333
}
}
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "select",
_target:
{
_ref: "layer",
_enum: "ordinal",
_value: "backwardEnum"
}
,
selectionModifier: {
_enum: "selectionModifierType",
_value: "addToSelection"
},
makeVisible: false,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "make",
_target:
{
_ref: "layerSection"
}
,
from:
{
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
}
,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "set",
_target:
{
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
}
,
to: {
_obj: "layer",
name: "Frequency Separation 8bit"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "select",
_target:
{
_ref: "layer",
_name: "Frequency Separation LF"
}
,
makeVisible: false,
layerID:
64
,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "select",
_target:
{
_ref: "brush",
_name: "Wet Brush FS MEDIAN LOW"
}
,
_options: {
dialogOptions: "dontDisplay"
}
}
],{
synchronousExecution: false,
modalBehavior: "wait"
});
}
document.querySelector("#btnfsgaussian").addEventListener("click", fsgaussian)
What am I doing wrong? I’ve heard something about API changes and executeAsModal but I have no idea if it’s related.
When I’m debugging my plugin I’m getting one error related to API version but I don’t know how to update it to apiVersion 2. Maybe you could help with this as well?
Thank you all in advance, I will really appreciate your help!