Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Call 'Load Files Into Stack' from UXP plugin

Community Beginner ,
Mar 07, 2025 Mar 07, 2025

Copy link to clipboard

Copied

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;

TOPICS
Actions and scripting

Views

326
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Mar 08, 2025 Mar 08, 2025

Thank you for your quick response. I suspect a runtime error which I can't explain since the script "Load Files into Stack" started loading files into stack but got stuck after the first file was loaded into a layer. I then set a delay function which helped. Now the script runs like charm. Still don't now why this works... but it does. Thank you all again for your support.

import { core, action } from "photoshop";
const { executeAsModal } = core;
const { batchPlay } = action;

console.log("LoadFilesI
...

Votes

Translate
Adobe
Community Expert ,
Mar 07, 2025 Mar 07, 2025

Copy link to clipboard

Copied

Adobe need to update all of their old .JSX scripts for. .PSJS or UXP panels. I believe it's one technology or the other as they can't be mixed.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 08, 2025 Mar 08, 2025

Copy link to clipboard

Copied

I created a small focus stacking panel with a donation option Here is the link https://sites.google.com/view/openpaneluxp/focus-stacking

As you can see from the video I did not use the option to open the dialog box, I tried to do it all automatically. The only problem I had was loading the nef - raw files in photoshop, using uxp opened the nef in photoshop and not in camera raw, so I opted to insert a . Jsx file inside the panel. I looked around and I did not find any documentation for this. Unfortunately some things in uxp still need to be perfected and javascript programming is still needed I'm not at home now, after I get back I'll take a look at your script and if I can help you I'll do it willingly.

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/uxp-open-file-in-photoshop-mac-not-wo... 

 

see if this works for you

 

async function stack() {
    let result;
    let psAction = require("photoshop").action;

    let command = [
        // Script
        {"descriptor": {"_obj":"AdobeScriptAutomation Scripts","javaScriptName":"Carica file in serie..."}, "options": {"dialogOptions": "display"}}
    ];
    result = await psAction.batchPlay(command, {});
}

async function FunctionStack() {
    await require("photoshop").core.executeAsModal(stack, {"commandName": "Action Commands"});
}

await FunctionStack();

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 08, 2025 Mar 08, 2025

Copy link to clipboard

Copied

Thank you for your quick response. I suspect a runtime error which I can't explain since the script "Load Files into Stack" started loading files into stack but got stuck after the first file was loaded into a layer. I then set a delay function which helped. Now the script runs like charm. Still don't now why this works... but it does. Thank you all again for your support.

import { core, action } from "photoshop";
const { executeAsModal } = core;
const { batchPlay } = action;

console.log("LoadFilesIntoStack.js loaded");

// Helper function to create a delay
function delay(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function loadFilesIntoStack() {
  console.log("Executing 'Load Files into Stack'...");

  try {
    // Call the script
    const result = await batchPlay(
      [
        {
          _obj: "AdobeScriptAutomation Scripts",
          javaScriptName: "Load Files into Stack...",
          javaScriptMessage: "undefined",
          _isCommand: false,
          _options: {
            dialogOptions: "display"
          }
        }
      ],
      {
        synchronousExecution: true,
        modalBehavior: "execute"
      }
    );
   
    console.log("Script initiated, waiting for completion...");
   
    // Add a significant delay to allow the script to finish processing all files
    await delay(1000); // 1 seconds delay
   
    console.log("Files loaded into stack successfully.", result);
    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",
      interactive: true // Ensure interactive mode is enabled
    });
  } catch (error) {
    console.error("Error running modal function:", error);
  }
}

export default runModalFunction;

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 08, 2025 Mar 08, 2025

Copy link to clipboard

Copied

That's great! It reminds me of AppleScript having the ability to either run JSX "inline" or by calling an external JSX file to accomplish tasks outside of the AS DOM.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 08, 2025 Mar 08, 2025

Copy link to clipboard

Copied

Opps, The script you posted doesn't work for me?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 09, 2025 Mar 09, 2025

Copy link to clipboard

Copied

Hi Ciccillotto,

Just to make it more clear to you how I'm using this script... The script is in a separate js-file file. I have an index.html file for the sp-picker. I'm using to call the script. This is achieved by an event listener in main.js to call the native modal Photoshop script 'Load Files into Stack". If it doesn't work for you it's probably because of how you call the script.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 09, 2025 Mar 09, 2025

Copy link to clipboard

Copied

Thanks for the replying.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 13, 2025 Mar 13, 2025

Copy link to clipboard

Copied

Hi! I have this problem too, I have zero idea how to fix it. I'm on a PC. And this happens to me as well, I try to load files into stack to make gifs and after the first one opens, the screen loads and then just gets rid of it completely. I don't know anything about scripts. Please help.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2025 Mar 13, 2025

Copy link to clipboard

Copied

quote

Hi! I have this problem too, I have zero idea how to fix it. I'm on a PC. And this happens to me as well, I try to load files into stack to make gifs and after the first one opens, the screen loads and then just gets rid of it completely. I don't know anything about scripts. Please help.


By @theladyash

 

If you know nothing about scripts and are not calling the legacy ExtendScript code from the new UXP framework, then you would be best to create a new topic as your situation isn't the same and piggybacking onto this topic will provide less visibility and limit the potential help you may receive.

 

Edit: You could try some simpler, alternative stacking scripts:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/combining-tiffs/m-p/13475955

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/layers-creating-layers/td-p/13252109

 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 14, 2025 Mar 14, 2025

Copy link to clipboard

Copied

LATEST

If you can open a new post it's better, If it's for uxp I posted a script above, see if it works, If you already have a script post it and we'll see where the error is.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines