Hi,
Is there a way to synchronously perform executeAsModal on every selected layer from activeLayers array? I tried to await executeAsModal promise and even then it breaks that synchronous operation and gives incorrect result (some transformations are applied before others and sometimes multiple times in a row before others are applied).
Here is some sample to code for what I want to achieve:
const handleExecution = async () => {
// Check if there is any active document before executing the function
if (!app.activeDocument) {
await app.showAlert("No active document!");
return;
}
const originalLayers = app.activeDocument.activeLayers;
originalLayers.forEach(async (layer) => {
await transformLayer(layer)
});
});
};
And the code for transformLayer function:
import { app, constants, core } from "photoshop";
import { Layer } from "photoshop/dom/Layer";
export const transformLayer= async (
layer: Layer
) => {
try {
await core.executeAsModal(
async () => {
const newLayer = await layer.duplicate();
newLayer .selected = true;
newLayer .name = "New layer";
await newLayer.scale(100, 50, constants.AnchorPosition.BOTTOMCENTER);
newLayer.opacity = 50;
newLayer.move(layer, constants.ElementPlacement.PLACEAFTER);
newLayer.link(layer);
newLayer.selected = false;
layer.selected = true;
},
{ commandName: "Creating a transformed layer..." }
);
} catch (e) {
console.log(e);
}
};