Hi,
Figma allows you to convert an a node and all of it’s children to an Image via rightclick>copy as png. Then paste and good to go.
I would love to be able to do that from within my plugin. like
(sudo code)
ImageFromNode = figma.copyNodeAsPNG;
newNode = figma.createRectangle;
newNode.position = sourceNode.position;
newNode.size = sourceNode.size;
newNode.fill = new Fill(“IMAGE”);
newNode.fill.image = ImageFromNode;
What I have found here on the forums is the start.
async function getArtwork () {
var selected = figma.currentPage.selection[0];
if (!selected) return;
try {
return selected.exportAsync({format: 'PNG'}).then(data => {
return { selected, data };
}).catch(e => { return e; });
} catch (err) {
return err }
}
Struggling a bit with the rest and wonder if I can’t just use Figma’s already existing functions to do so as I am sure the rightclick ability to do so just triggers some function.
Thank you.