is failing when trying to read rendered artboards



I’m writing a plugin where I need to bake (create renditions of) the available artboards and
do some additional steps using the generated files.

I’m using application.createRenditions() and it all woks and generates the baked artboards.
The images are stored in the getTemporaryFolder().

Refer to the attached screenshot and log to see that the marked log line from the following code snippet is being printed and all meta information about the file seems correct.

The issue is that the next line calling is failing silently:

  • no errors in the console;
  • there are no following log lines for the other files;
.then(() => {
    console.log('Baking done!');
    let filePromises =[]; => {
            folder.getEntry( + '.jpg')
    .then(bakedFiles => {
        console.log('Opened files: ' + bakedFiles.length);
        let readPromises = []; => {
            // ########
            console.log(bakedFile.toString()); // this log gets printed
            // ########
      {format: formats.binary})

Steps to reproduce

  1. application.createRenditions(…);
  2.{format: formats.binary});

Expected Behavior

I was expecting to get the file content.

Actual Behavior

The execution seems to have just stopped without any error or warning.


Files prepared: 3
Baking 3 artboards.
Baking done!
Opened files: 3



Hi @valado welcome to the community!
as per our documentation, file read will return a promise, so you will have to await like:

const data = await{format: formats.binary}); // 'data' is an ArrayBuffer
console.log("File is " + data.byteLength + " bytes long.");


You may not see any console errors when thing go wrong if you’re not linking your Promises together in a chain (definitely some like readPromises and the Promise.all() result are not) and returning that entire chain to XD. It might be easier, as Steve mentioned, to use the await syntax instead of juggling Promises manually.

I think you can simplify this code a bunch though and that may make it easier to figure out what’s going wrong. The createRenditions() call gives you File objects for the results, so you don’t need those getEntry() calls. Fyi, you also don’t need to use both map() and push() – pick one or the other.

The “How to export a rendition” sample code may be helpful to look at. But at a quick glance, I think you could do something like this:

return application.createRenditions(bakeTasks)
.then(results => {
    console.log("Baking done!");
    let readPromises = => {
        console.log("Reading " + result.outputFile.nativePath);
        return{format: formats.binary});
    return Promise.all(readPromises);
}).then(readResults => {
    readResults.forEach(arrayBuffer => {
        console.log("File is " + arrayBuffer.byteLength + " bytes");