Skip to main content
Solved

How are paintStyleIds created?

  • January 10, 2023
  • 4 replies
  • 642 views

ayush.kalani

Hello,

I am trying to create a map of all our paintStyleIds that we have stored in a Figma file. Purpose of doing that is to use semantic names of these paintStyles rather than their hex values.

I have a plugin which gets the values of all the current paint styles in a file (using figma.getLocalPaintStyles() ). When I look through the data that I get back from Figma,
I see that paintStyleId comes back truncated, something like this-
id: “S:407eaa3991e05cb0597e4da3fr728014dc7f0f3b56,”

The actual iid that works looks something like this-
id: “S:407eaa3991e05cb0597e4da3fr728014dc7f0f3b56, 3:78

I am trying to. understand where does this colon separated value after the comma comes from? I don’t see this data anywhere in the data I get back from Figma.

Any help is much appreciated.

Best answer by tank666

The value after the comma is specified only for styles that are imported from the library.

View original
This topic has been closed for replies.

4 replies

tank666
  • 4873 replies
  • Answer
  • January 10, 2023

The value after the comma is specified only for styles that are imported from the library.


ayush.kalani

Thank you for the quick response, @tank666

A follow up on what you mentioned.

I get the same paintStyle using below 2 IDs.

figma.getStyleById(’ S:407eaa3991e05cb0597e4da3fr728014dc7f0f3b56,3:78’)

figma.getStyleById(’ S:407eaa3991e05cb0597e4da3fr728014dc7f0f3b56,')

But when I do-
node.fillStyleId = ‘S:407eaa3991e05cb0597e4da3fr728014dc7f0f3b56,’

I get this error-
error: “FigmaNode::attrib: key: fillStyleId, value: S:655c48b8a4b81aef75d65bfbebfad42c9a6246b1, name: Rectangle 1 type: RECTANGLE”

error: “in set_fillStyleId: Cannot set style successfully: Cannot find style”


tank666
  • 4873 replies
  • January 11, 2023

You should have received two different objects, but which have the same key property values.

You got this style id in the library file using figma.getLocalPaintStyles(), where the style is the local style.

You got this id in another file, where the style is a remote style and imported into this file.

You are getting this error in another file, right? Because this code will only work in the file where the style with this id is a local style. And since you’re trying to assign a remote style to a node, you need to specify the full id (with the value after the comma).


ayush.kalani

Thank you so much @tank666 . That was very helpful.


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