Skip to main content
Question

How to assign a range of text to a color variable? setRangeFillVariableId method?


Bradley_Kounter

Is there a method for setting/assigning a range of text to a variable? I noticed that even the setRangeBoundVariable(start, end, type, variableId) doesn’t support “color” for the type.

Something like:

figma.currentPage.selection[0].setRangeBoundVariable(0, 5, 'color', 'VariableID:313:879')

Which would then apply that variable to text characters 0-5.

This topic has been closed for comments

2 replies

James_Yang
Figmate
  • Figmate
  • 82 replies
  • June 29, 2024

Text color is managed in the fills property, so you need to use setRangeFills:

figma.currentPage.selection[0].setRangeFills(
  0, 
  5, 
  [
    { 
      type: 'SOLID', 
      color: { r: 0, g: 0, b: 0 }, 
      boundVariables: { color: { type: 'VARIABLE_ALIAS', id: 'VariableID:2:5' } } 
    }
  ]
)

Bradley_Kounter

Yessss! That totally worked. Thank you!


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