Export Layers to file individually

Hey there!

I’m developing my first plugin with UXP and I would like to know if it’s possible to export each layer to a separate file, something like the createRenditions in Adobe UXD?

If it’s not possible, this will be in the photoshop uxp plugin roadmap?

Thanks in advance!

Hi there!

Welcome to the forum.

You can definitely go to File --> Export --> Layers to Files through the Photoshop menu. But is that reachable via UXP?

If it isn’t, you could try using the Alchemist plugin to “listen” for the event. Check out @DavideBarranca’s video here: https://www.youtube.com/watch?v=aZn_6X6nvUM - that particular video has some listening and layer commands you may find useful (and all the videos in that series are very helpful!)

2 Likes

Thanks so much!

After other topic I created, I was trying this listener and layers export in other way and weren’t working, buuuut this way File --> Export --> Layers worked like a charm!

Again, thanks so much :))

Hello again!

This generated a code and rendered all layers as well, but the code that Alchemist gave to me when I try to execute I hae the following error:


The code tha Alchesmit gave to me is:

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
[
   {
      "_obj": "6f1c2cf5-4a97-4e32-8f59-f5d7a087adef",
      "message": "Configurações da ação Exportar Camadas para Arquivos",
      "destination": "Z:\\destination\\path\\layers",
      "fileNamePrefix": "layer:",
      "visibleOnly": true,
      "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,
      "_isCommand": true,
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": false,
   "modalBehavior": "fail"
});

I noticed that the alert error was in Portuguese, the translated message would be:

Error 54: Javascript Exception not caught: Error: Unsupported type in descriptorToObject DescValueType.INTEGERTYPE, line:2455
-> throw (new Error("Unsupported type in descriptorToObject" + t) );

Do you know what could it be? :frowning:

Perhaps fileType 7 is the wrong number? :thinking:
Maybe @Jarda can help…

1 Like

No, I don’t think so.

I tried to export to other file types like PDF, JPEG, PNG (their file types number are different) and the error message is the same :confused:

Perhaps it’s more of a @Barkin question…

It could be possibly caused by file path since in UXP you need tokens instead and I am not sure if that JSX script accepts it as a path or string data type.

Or maybe you do use strings instead of numbers.

I think it’s about this way, because changing the file type argument to String the error changed and it is:

Error: Unsupported type in descriptorToObject DescValueType.OBJECTTYPE

Or enums could be a problem. Since enum is in fact number but you pass it as string. So I am not sure how this is translated on the other side.

I’m little lost, I tried a lot of different things here.
Do you have any idea of what I could do?

Definitely fix the File path – it’ll cause problems regardless of the rest of it.

See https://www.adobe.io/photoshop/uxp/uxp/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/#createsessiontokenentry for an example.

@kerrishotts that is not sure. Because this UXP batchPlay calls ExtendScript. It can pass the path as a string and on the other side, it will convert the string type into a file path type and use it in its own executeAction() …it would be a nice hack :smiley:

So, Fixing the file path does not change the error message, I tried the following:

const fs = require('uxp').storage.localFileSystem;
let entry = await fs.getFolder();
let token = fs.createSessionToken(entry);

And then changed the filePath to use this token, but the error message is the same. @Jarda said something about the fileType and I think may be it, because the error message changed when I tried to use a string instead of an integer (but I don’t know, just hunches).

1 Like