In below sample code,
Blockquote
export async function test()
{
const selection = Figma.currentPage.selection;
console.log("Selection length is ",selection.length)
if (selection.length > 0) {
const node = selection[0] as SceneNode;
console.log("node is",node.name)
**const imageData = await exportImage(node);**
console.log("POSTING....",imageData)
figma.ui.postMessage({ type: 'imageData', imageData: imageData }); // Sending the image data back to the UI
}
else
{
console.warn('No layers selected.');
}
}
async function exportImage(node: SceneNode): Promise {
return new Promise((resolve) => {
const tempFrame = Figma.createFrame(); // Create a temporary frame
tempFrame.resize(node.width, node.height);
tempFrame.appendChild(node.clone()); // Clone and add the scene node to the temporary frame
const exportSettings: ExportSettingsImage = { format: âPNGâ };
tempFrame.exportAsync(exportSettings).then((imageBytes) => {
tempFrame.remove(); // Remove the temporary frame
resolve(imageBytes);
});
console.log(âOKâ)
});
}
Blockquote
const imageData = await exportImage(node);
The call to exportImage is getting stuck. It is not returningâŚ
But if I remove await there, it is returning but imageData is nothing. Could I ask what is wrong?