Untitled

mail@pastecode.io avatar
unknown
typescript
3 years ago
1.2 kB
2
Indexable
Never
figma.showUI(__html__);

figma.ui.onmessage = msg => {
    if (msg.type === 'generate') {
    let selectedElement = figma.currentPage.selection.length

    if (selectedElement === 0) {
        figma.closePlugin('No element selected!')
    }

    if (selectedElement > 1) {
        figma.closePlugin('Please select one component node!')
    }

    // récupérer les langues et itérer
    // name = screenshot_position_language

    let cl = figma.currentPage.selection[0].clone()
    cl.name = "test 2"
    

    let count = 0
    async function traverse(node) {
      if ("children" in node) {
        count++        
        if (node.type !== "INSTANCE") {
          for (const child of node.children) {
            if (child.type === "TEXT"){
              // translate child.characters

              await figma.loadFontAsync(child.fontName);
              child.characters = 'TESTING'
            }

            traverse(child)
          }
        }
      }
    }
    
    traverse(figma.getNodeById(cl.id))
    console.log(count)

    figma.currentPage.selection[0].x = figma.currentPage.selection[0].x +  figma.currentPage.selection[0].width + 1000

      console.log('HUHA3')
    }
  // figma.closePlugin();
};