Skip to main content
Pavel_Kiselev
Power Member
Jun 27, 2023 3:35 AM UTC
Question

How to use setBoundVariableForPaint

I would appreciate some guidance on figma.variables. setBoundVariableForPaint method.

figma.com

I would like to run a simple script to bind a variable to the existing style. This is what I tried

// get a style ref
let style = figma.getLocalPaintStyles()[0];
// get a var ref
let variable = figma.variables.getVariableById("VariableID:1:53");
// bind?
figma.variables.setBoundVariableForPaint(style.paints[0], 'color', variable);

It returns a solid paint indeed, however, it has no effect on a given style. Confusing…

This topic has been closed for replies.

12 replies

Pavel_Kiselev
Power Member
Aug 18, 2023 5:56 AM UTC

And another one that goes other way around - it takes local colour styles and makes variables out of them

tinaciousdesign
Sep 24, 2024 11:52 PM UTC

This is great! I had been creating blank colour variables, turns out I was missing setValueForMode. Thanks for this!