Call 'Load Files Into Stack' from UXP plugin
With my uxp plugin I call the native Photoshop script “load files into stack”. I can successfully load it from UI and can select layers to be loaded into stack. Unfortunately the script stops after the first file has been loaded into stack albeit I have selected more than 1 file to be loaded into stack. Currently, there seems to be no direct Photoshop API feature that returns the quantity of selected files or that waits automatically for all files to load when using the native “load files into stack” command. Has someone found a solution to overcome this problem or can you suggest a solution? Here is the code of my LoadFilesIntoStack.js file:
import { core, action } from "photoshop";
const { executeAsModal } = core;
const { batchPlay } = action;
console.log("LoadFilesIntoStack.js loaded");
async function loadFilesIntoStack() {
console.log("Executing 'Load Files into Stack'...");
try {
const result = await batchPlay(
[
{
_obj: "AdobeScriptAutomation Scripts", // Corrected object name
javaScriptName: "Load Files into Stack...", // Corrected script name
javaScriptMessage: "undefined", // This matches Alchemist output
_isCommand: false, // This was also part of Alchemist output
_options: {
dialogOptions: "display" // Ensures the UI is shown
}
}
],
{
synchronousExecution: true,
modalBehavior: "execute"
}
);
console.log("Files loaded into stack successfully.", result);
return result; // Capture and return result
} catch (error) {
console.error("Error executing 'Load Files into Stack':", error);
}
}
async function runModalFunction() {
try {
return await executeAsModal(loadFilesIntoStack, { commandName: "Load Files into Stack" });
} catch (error) {
console.error("Error running modal function:", error);
}
}
export default runModalFunction;
