How are paintStyleIds created?


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.

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

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”

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).

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