Skip to main content
Solved

Can't get color in some nodes


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.

Best answer by tank666

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

View original

3 replies

tank666
  • 4854 replies
  • January 27, 2024

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


  • Author
  • 1 reply
  • January 28, 2024

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


tank666
  • 4854 replies
  • Answer
  • January 28, 2024

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


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