Skip to main content
Question

Getting error in setBoundVariableForLayoutGrid


Figterate

Hello,

I am trying to apply grid variable using below code by following Working with Variables | Plugin API guide.

Error : Expected “layoutPattern” to have type “GRID” but got string instead

We are trying to create a copy of layoutgrid and apply new variable using below code

let propCopy = [...node.layoutGrids];
propCopy[0] = figma.variables.setBoundVariableForLayoutGrid(
    propCopy[0],
   "gutterSize",
    variable
  );
 node.layoutGrids = propCopy;

propCopy[0] is as below

{alignment: "STRETCH",
boundVariables: {offset: {…}, sectionSize: {…}, count: {…}, gutterSize: {…}},
color:  {r: 1, g: 0, b: 0, a: 0.10000000149011612},
count: 4,
gutterSize: 20,
offset: 100,
pattern: "ROWS",
visible: true}

But after executing, we are getting below error:

in setBoundVariableForLayoutGrid: Expected "layout…ttern" to have type "GRID" but got string instead
mesage: "in setBoundVariableForLayoutGrid: Expected "layoutGridCopy" to be one of the following, but none matched: \n  Expected "layoutGridCopy.alignment" to be one of the following, but none matched: \n    Expected "layoutGridCopy.alignment" to have type "MIN" but got string instead\n    Expected "layoutGridCopy.alignment" to have type "MAX" but got string instead\n  Expected "layoutGridCopy.boundVariables" to have type {gutterSize: (optional) {id: string, type: "VARIABLE_ALIAS"}, count: (optional) {id: string, type: "VARIABLE_ALIAS"}, offset: (optional) {id: string, type: "VARIABLE_ALIAS"}} but got additional property "sectionSize"\n  Expected "layoutGridCopy.alignment" to have type "CENTER" but got string instead\n  Expected "layoutGridCopy.pattern" to have type "GRID" but got string instead"

Please help.

Thank you

This topic has been closed for replies.

2 replies

Figterate
  • Author
  • 1 reply
  • April 3, 2024

[quote=“Figterate, post:2, topic:68498, full:true”]
We checked it again by manually updating layout grid one by one for each property. And found that it is causing error only for below use case:

  1. Select ROW pattern and MIN alignment (top type in UI), apply variable in offset and size
  2. Change alignment to CENTER and then use setBoundVariableForLayoutGrid to update size variable.

In this case boundVariable still contains offset entry but in CENTER it should be ignored. We also tried to remove it by passing null to setBoundVariableForLayoutGrid as below but in this case also we got same error

setBoundVariableForLayoutGrid: Expected "layout…ttern" to have type "GRID" but got string instead

layoutGrid = figma.variables.setBoundVariableForLayoutGrid(
            layoutGrid,
            "offset",
            null
          );

Same happened with STRETCH alignment and having variable attached in sectionSize.


@Figterate The same is happening to me, did you find a solution to this, or is it a bug? If so, have you reported it directly to Figma?


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