Skip to main content
Question

Children of Frame returned an empty array, but visible in console


carter1

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

3 replies

Carter_Xiao

(post deleted by author)


carter1
  • Author
  • New Member
  • 2 replies
  • July 31, 2022

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.


carter1
  • Author
  • New Member
  • 2 replies
  • August 5, 2022

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;
}

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings