Skip to main content
Solved

Cannot access node properties

  • November 9, 2021
  • 2 replies
  • 2013 views

Mihai_Olteanu

Hi guys,

In my plugin I’m trying to find all component nodes so I can get their “key” property, however I am unable to access the “type” property of any of the nodes in my document so that I can filter out accordingly.

I have identified the id of one of the nodes I want to access and used const node = figma.getNodeById(nodeId) to check its properties however the outputted Node object doesn’t seem to have any accessible properties other than id (example output: {id: "119:2745"}).

Similarly, if I try node.type on any node returned by figma.root.findAll() or figma.currentPage.selection, it returns undefined. The only property that works is node.id.

Could there be something wrong with how my project is set up or am I missing something in accessing a node’s properties?

Best answer by tank666

Everything should work. Perhaps the problem is caused by your code.

Expand all the properties of the node by clicking on the triangle to the left of the object in the console.

For example:

> TextNode {id: "0:1"}

You can also check this code right in the Figma console, which will output the node type. Preselect any layer.

figma.getNodeById(figma.currentPage.selection[0].id).type
View original
This topic has been closed for comments

2 replies

tank666
  • 4854 replies
  • Answer
  • November 9, 2021

Everything should work. Perhaps the problem is caused by your code.

Expand all the properties of the node by clicking on the triangle to the left of the object in the console.

For example:

> TextNode {id: "0:1"}

You can also check this code right in the Figma console, which will output the node type. Preselect any layer.

figma.getNodeById(figma.currentPage.selection[0].id).type

Mihai_Olteanu

Hi Yury,

The above code did work and it helped me realise that I was sending the list of Node objects to the plugin UI to extract and display the properties, instead of extracting the properties first then post that to the UI.

Many thanks for your help!


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