Hi @simonhenke,
Thank you so much for your help, I really appreciate it!
What exactly is not working? Do you get an error, unexpected behavior or is simply nothing happening?
Unfortunately nothing happened. I didn’t get an error in console as well.
I’m not a developer so I’m doing many things by tests and tries but I’m lacking a lot of basic knowledge
I’m trying to constantly learn new things and this community (including you) is helping me al lot.
In this case I suppose that it could be a matter of my mistakes in merging my function with @Karmalakas code.
I’ve noticed that we’re calling executeAsModal in different way.
I’m using
await core.executeAsModal(() => {
batchPlay(
[
and @Karmalakas :
executeAsModal(async () => {
batchPlay(
I’m also not using this part in my descriptors:
synchronousExecution: true,
modalBehavior: 'execute'
Is this the difference in API / manifest version or these methods can be used interchangeably?
I’ve tried to split my batchplay into two and to place @Karmalakas code in the middle like shown below but it didn’t work.
async function dustAndScratches() {
const docexists = () => {
return Boolean(app.documents?.length)
}
const exists = docexists()
if (exists === true) {
await core.executeAsModal(() => {
batchPlay(
[{
_obj: "make",
_target: {
_ref: "layer"
},
layerID: 222,
_options: {
dialogOptions: "dontDisplay"
}
}
], {
"historyStateInfo": {
"name": "Dust and Sctartches pt1",
"target": {
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
}
});
// added code
// I guess that this line was missing (you probably had it specified globally):
const doc = app.activeDocument;
// Get top-most layer
const topLayer = doc.layers[0]
// Get index of that layer
const topIndex = batchPlay(
{
_obj: 'get',
_target: [
{_property: "itemIndex"},
{_ref: 'layer', _id: topLayer.id},
{_ref: 'document', _id: docId}
],
_options: {dialogOptions: 'dontDisplay'}
},
{
synchronousExecution: true,
modalBehavior: 'execute'
}
)[0].itemIndex
// Move other layer to that index
executeAsModal(async () => {
batchPlay(
{
_obj: 'move',
_target: [{_ref: 'layer', _enum: 'ordinal', _value: 'targetEnum'}],
to: {_ref: 'layer', _index: topIndex},
adjustment: false
},
{
synchronousExecution: true,
modalBehavior: 'execute'
}
)
// you had here:
// }, {"Command name"})
// but I was getting an error - ':' expected. so I've replaced it with:
}, {
"historyStateInfo": {
"name": "Dust and Sctartches pt2",
"target": {
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
}
})
// end of added code
batchPlay(
[
{
_obj: "move",
_target: {
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
},
to: {
_ref: "layer",
_enum: "ordinal",
_value: "front"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "move",
_target: {
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
},
to: {
_ref: "layer",
_enum: "ordinal",
_value: "front"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "mergeVisible",
duplicate: true,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "set",
_target: {
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum"
},
to: {
_obj: "layer",
name: "Dust and Scratches"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "select",
_target: {
_ref: "menuItemClass",
_enum: "menuItemType",
_value: "view200Percent"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "dustAndScratches",
_options: {
dialogOptions: "display"
}
},
{
_obj: "make",
new: {
_class: "channel"
},
at: {
_ref: "channel",
_enum: "channel",
_value: "mask"
},
using: {
_enum: "userMaskEnabled",
_value: "revealAll"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "invert",
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "select",
_target: {
_ref: "channel",
_enum: "channel",
_value: "mask"
},
makeVisible: false,
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "select",
_target: {
_ref: "paintbrushTool"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "reset",
_target: {
_ref: "color",
_property: "colors"
},
_options: {
dialogOptions: "dontDisplay"
}
},
{
_obj: "select",
_target: {
_ref: "menuItemClass",
_enum: "menuItemType",
_value: "fitOnScreen"
},
_options: {
dialogOptions: "dontDisplay"
}
}
], {
"historyStateInfo": {
"name": "Dust and Sctartches pt3",
"target": {
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
}
});
})
}
else { PhotoshopCore.showAlert({message: 'Open the document first'});}
}
document.querySelector("#btndustAndScratches").addEventListener("click", dustAndScratches);
Your suggestion on history suspension is great, I’ll have to test it as well. It’s a shame though that each BatchPlay instance within one executeAsModal needs to have own history state.
Thanks!