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.
You’ve got the first step covered already: exporting the image. Just need to fix some issues with async. And your pseudo-code logic is correct, only instead of copying as png you need to export the image.
That is too bad. It was a feature I really loved about 3DS Max, any action you performed in the editor, the command was output to the log so if you wanted to write code, you could just perform the actions manually, watch to log and then hack things together.
All good, this is where I am so far. Is this the right track?
// LETS do IMAGE STUFF!
function ConvertNodeToImage(){
var unit8 = getArtwork();
var img = figma.createImage(unit8);
var newRect = figma.createRectangle();
// Fill new Rect fill with image data.
}
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 }
}
I have been trying to find a code example of someone filling a fill with image data in memory. The documentation on working with images helps but it is skipping the reapply stage which is what I am looking for. Any ideas?