Skip to main content
January 27, 2024
Solved

Can't get color in some nodes

  • January 27, 2024
  • 3 replies
  • 427 views

Pretty new with this.

I want to make a plugin to select the right nodes (vectors within an illustration, which is an instance) with certain color and this code works with one component instance but not another. It happens on about 20% of the illustrations I have although they have no discernable difference.

let rightElements = myIllustration[0].findAll(n => n.type === 'VECTOR' && n.fills[0].color.r === 1)
figma.currentPage.selection = rightElements

The error is
figma_app.min.js.br:7 Error: in findAll: "findAll" callback crashed: TypeError: cannot read property 'color' of undefined

I can’t see any discernable difference between the nodes in each instance. They are all vectors, the exact same color. I am able to get the color when I click on the vector I wanted to select and do a console log.

This topic has been closed for replies.
Best answer by tank666

Write a condition where you check each property to make sure it exists.

3 replies

tank666
January 27, 2024

Some node does not have fills, so it is impossible to access the properties along this path.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
akqAuthor
January 28, 2024

Thanks! How can I use findAll only for nodes with fills?

tank666
tank666Solution
January 28, 2024

Write a condition where you check each property to make sure it exists.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank