Skip to main content
Solved

Clone node

  • September 30, 2021
  • 7 replies
  • 3473 views

1111357

Good day!

How can i clone or copy node?

I want get selection nodes from page (currentPage.selection)

Clone selection nodes and group

Export group to image and submit image to REST API url

Or is there another way, to get one image from selection nodes?

Best answer by 1111357

You are right, thank you very much!

Ts ignore help me =) and nodes success cloned and grouped

// @ts-ignore
selectedNode.forEach(node => clonedNodes.push(node.clone()))
View original
This topic has been closed for replies.

7 replies

1111357
  • Author
  • 3 replies
  • September 30, 2021

Need NODES (all) save to one IMAGE

I know, that i can group nodes, and group export to image…

But group with original nodes are not good for me, don’t want doing manipulation with original user nodes

Excelent if i take selection nodes, create temp group with clone selection nodes, export image and remove temp group


Gleb
  • Power Member
  • 4708 replies
  • October 1, 2021

You can clone each node by calling node.clone(), push this cloned node to an array and then put this array into figma.group(nodesArray, parentNode) to create a group from them. group · Figma Developers


1111357
  • Author
  • 3 replies
  • October 1, 2021

Property ‘clone’ does not exist on type ‘SceneNode’.

  switch (msg.type) {
    case MessageTypes.select:
      const { currentPage } = figma
      const selectedNode = currentPage.selection;

      if (selectedNode.length > 0) {

        const clonedNodes: SceneNode[] = []

        selectedNode.forEach(node => clonedNodes.push(node.clone()))

        const group = figma.group(clonedNodes, currentPage)
      }
      break;
    case MessageTypes.cancel:
      figma.closePlugin();
      break;
  }

Not work

selectedNode.forEach(node => clonedNodes.push(JSON.parse(JSON.stringify(node.clone()))))

Снимок экрана 2021-10-01 в 10.45.25


Gleb
  • Power Member
  • 4708 replies
  • October 1, 2021

1111357
  • Author
  • 3 replies
  • Answer
  • October 1, 2021

You are right, thank you very much!

Ts ignore help me =) and nodes success cloned and grouped

// @ts-ignore
selectedNode.forEach(node => clonedNodes.push(node.clone()))

Pablo_Romero

@ts-ignore will disable TS for the rest of the file. Maybe you can do: (node as ComponentNode).clone()


Gleb
  • Power Member
  • 4708 replies
  • November 22, 2021

This topic was automatically closed after 15 days. New replies are no longer allowed.


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