Export Layers to file individually

I managed to get it to work, without it throwing the “Unsupported type in descriptorToObject”.
I commented all the other options that might be causing the issue hoping that they would have a default value, and it seems as though they do. Also, I am saving the a folder which UXP allows me to write to:
const dataFolder = (await UXP.storage.localFileSystem.getDataFolder()).nativePath.replace(/\\/g, "\\\\")

I have yet to try if it works in .getTemporaryFolder() too.

{
    _obj: "6f1c2cf5-4a97-4e32-8f59-f5d7a087adef",
    message: "Export Layers To Files action settings",
    destination: "C:\\Users\\USERNAME\\AppData\\Roaming\\Adobe\\UXP\\PluginsStorage\\PHSP\\25\\Developer\\ADOBE_PHOTOSHOP_PLUGIN_NAME\\PluginData",
    fileNamePrefix: "test",
    // visibleOnly: false,
    // fileType: "7",
    // icc: true,
    // jpegQuality: "8",
    // psdMaxComp: true,
    // tiffCompression: "TIFFEncoding.NONE",
    // tiffJpegQuality: "8",
    // pdfEncoding: "PDFEncoding.JPEG",
    // pdfJpegQuality: "8",
    // targaDepth: "TargaBitsPerPixels.TWENTYFOUR",
    // bmpDepth: "BMPDepthType.TWENTYFOUR",
    // png24Transparency: true,
    // png24Interlaced: false,
    // png24Trim: true,
    // png8Transparency: true,
    // png8Interlaced: false,
    // png8Trim: true,
    // _options: { dialogOptions: "dontDisplay" }
}

Thanks for the code! So much
But where does those code from? I also used Alchemist but no info ( maybe I’m dumb)

Where did you get this? And did you manage to use those options? Thanks

This code is helping me a lot. I modified to javascript. It works nicely when exporting only one layer. But I want to modify the function to get an array of layers as an input. It doesn’t quite work, photoshop is overwriting the files on top of each other, instead of exporting every layer with different names. My file has unique layer naming.
Do you see where is the error on my logic?

async function exportLayerAsPngTestMultipleCommands(layers, path){
try {

let commands = ;

for (let i = 0; i < layers.length; i++) {

  const id = layers[i].id;

  selectCommand = 	  {
  _obj: 'select',
  _target: [
      {
  	_ref: 'layer',
  	_id: id,
      },
  ],
  makeVisible: false,
  layerID: [id],
  _isCommand: false,
  }

  const exportCommand = {
  _obj: 'exportSelectionAsFileTypePressed',
  _target: { _ref: 'layer', _enum: 'ordinal', _value: 'targetEnum' },
  fileType: 'png',
  quality: 32,
  metadata: 0,
  destFolder: path, //destFolder.nativePath,
  sRGB: true,
  openWindow: false,
  _options: { dialogOptions: 'dontDisplay' },
  };

        commands.push(selectCommand);
  commands.push(exportCommand);

}

await core.executeAsModal(
async () => {
await action.batchPlay(commands, { modalBehavior: ‘execute’, synchronousExecution:false });
},
{ commandName: Export layers As PNG start }
);

} catch (error) {

console.error(error);
}

}

Btw I tried to run your original function inside a for loop, and I get also the issue of the files being overwritten. I guess I’m using BatchPlay in the wrong way. Is difficul to find official documentation of batchplay, how did you find keywords like ‘exportSelectionAsFileTypePressed’? This post seems to be the only place on the internet where that is mentioned :smiley:

Best regards,
Mango

For my case, I only run one pairs of selectCommand and exportCommand in action.batchPlay. It means for multiple layers, l did multiple batchPlays in a loop, it would be slower compared to single call of batchPlay, but I need to do it to get through all the layers in one psd.