Can someone confirm that createRenditions is working when using the await keyword?
I’ve created a test function to get the ArrayBuffer after exporting a rendition to png:
/**
* Get the image Array Buffer from scene node
* @param {SceneNode} element scene node
* @param {Number} scale scale of image. default is 2 to maintain quality
* @param {String} type type of image, png or jpg
* @param {Number} quality quality of image. number from 1 to 100. only for jpg
* @returns {Object}
**/
async function getArrayBufferFromSceneNode(element, scale = 2, type = "png", quality = 100) {
const application = require("application");
const filesystem = require("uxp").storage;
var folder = await filesystem.localFileSystem.getTemporaryFolder();
var file = await folder.createFile(element.guid + "." + type, { overwrite: true });
var definition = {};
definition.node = element;
definition.outputFile = file;
definition.type = type;
definition.scale = scale;
definition.quality = quality;
const renditionResults = await application.createRenditions([definition]);
const renditionsFiles = renditionResults.map(a => a.outputFile);
const renditionsFile = renditionsFiles[0];
const arrayBuffer = await renditionsFile.read({ format: filesystem.formats.binary });
arrayBuffer.length = arrayBuffer.byteLength;
return arrayBuffer;
}
Here is how to test it:
console.log("exporting");
var renditionResults = await getArrayBufferFromSceneNode(scenenode);
console.log("after first export");
var renditionResults = await getArrayBufferFromSceneNode(scenenode);
console.log("after second export");
Would a forEach() loop break await?
item.children.forEach(async function(item, i) {
await getBase64DataModel(item, model, artboardModel);
})