Skip to main content
Solved

How to get the typography's name

  • September 19, 2023
  • 4 replies
  • 761 views

I’m currently creating a codegen plugin and I need to get the , here is what I mean by “typography’s name” in edit mode:
image

I can get all the other data but not its name, which is what I actually need 🥲

Best answer by tank666

It’s because you didn’t get the style. To get the style you need to use the getStyleById method.

figma.com
This topic has been closed for replies.

4 replies

tank666
  • 4873 replies
  • September 19, 2023

Get the name of the text style.

figma.com

Thanks for the quick reply but they are not actually the same, name seems to refer to the node’s name as seen above the node and in the console (node.name) on this screenshot:

But i’m actually looking for the typography’s name, Desktop/Headings/H4 in the screenshot


tank666
  • 4873 replies
  • Answer
  • September 19, 2023

It’s because you didn’t get the style. To get the style you need to use the getStyleById method.

figma.com

Oh I see, thanks a lot!

For anyone stumbling upon this issue, here’s a minimal example:

figma.codegen.on("generate", async (e: CodegenEvent) => {
  const node = e.node;

  if (node.type === "TEXT") {
    console.log(figma.getStyleById(node.textStyleId).name);
  }
})