Skip to main content
Solved

Issue applying max-width and max-height properties for text layers in auto-layout using plugin API


Leon10

I’m developing a Figma plugin that pastes frames onto the canvas using the Plugin API. The frames are structured in JSON format and include nested auto-layout frames with text layers inside them. These text layers are set to “hug” content with specified max-height and max-width properties.

When pasting the frames, all elements are translated and positioned correctly. The text layers are nested within the auto-layout frames and have the layout value set to “hug.” However, the max-width and max-height properties are not being applied as expected.

The Figma app console displays the following error:
“Error applying maxHeight: Error: in set_maxHeight: Can only set maxHeight on auto layout nodes and their children.”

Has anyone else encountered similar issues or found a solution to this? Could this be a bug or a limitation within the Plugin API?

Best answer by James_Yang

The frames are structured in JSON format

Is it possible that when you’re iterating through the keys of the JSON, you’re setting maxHeight before applying auto-layout to the frame?

For example, the below code will fail, but if you switch the order of the last 2 lines, then it works.

const frame = figma.createFrame()
frame.maxHeight = 100
frame.layoutMode = 'VERTICAL'
View original
This topic has been closed for comments

2 replies

James_Yang
Figmate
  • Figmate
  • 82 replies
  • Answer
  • August 21, 2024

The frames are structured in JSON format

Is it possible that when you’re iterating through the keys of the JSON, you’re setting maxHeight before applying auto-layout to the frame?

For example, the below code will fail, but if you switch the order of the last 2 lines, then it works.

const frame = figma.createFrame()
frame.maxHeight = 100
frame.layoutMode = 'VERTICAL'

Leon10
  • Author
  • 2 replies
  • September 2, 2024

Thanks a lot James. Issue was indeed that maxHeight needed to be set after initial frame creation.


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