How to apply textStyles of a library?

I’m trying to apply a textstyle of a published library with a plugin.

I traced all the id’s of textstyles I need, preload them first using await figma.importStyleByKeyAsync(id) and wait till the styles have loaded.

But it seems in order to apply a style from a library you need to add a value (the 8222:188) behind the actual id of the textstyle, like textNode.textStyleId = "S:569fa12256875b98ce2fb5a946844108e7d5a3ee,8222:188". And the problem is that the additional value seems to be different from file to file in order to load the style…

Anyone have an idea how to solve this?

figma.importStyleByKeyAsync(key) imports a style into a file and returns a style object. Just store this object in a variable.

let style = await figma.importStyleByKeyAsync(key);
node.textStyleId = style.id;
1 Like

Tx, got it working!