Hi, I am new to Figma API
The Scene tree (screenshot) looks like this, my goal it to select all nodes named Cell
I have tried
- Double
forEach
, first iteration returned the Frame nodes alright, but not the Frame’s children…so second iteration only got back an empty array
- Also tried
findAll (node => node.name === "Cell ")
, nothing returned
However, they are accessible from console window (screenshot). Not sure where i did wrong
Answering my findAll
part of the question, turns out I should put
const cell = figma.createFrame();
cell.name = 'Cell';
before await figma.loadFontAsync(text.fontName);
otherwise the cell name will still be ‘Frame’. So the search works, I think the forEach
also has something to do with Async createText()
, still not sure why.
answer my own question again, double forEach
works I don’t know why it’s not working eariler.
const allSelect = () =>{
const selection = [];
const mainFrame = figma.currentPage.findAll((node) => node.name === 'Mainframe-'+ id);
mainFrame[0].children.forEach ((node) => {
node.children.forEach((child) => {
if (child.name = 'Cell') {
selection.push(child);
}
}
);
} );
return selection;
}