So I’ve isolated a component node, now that I have it, how do I get the styles that are applied to it? I want to get the color and text styles so that I can match them to local style names.
const nodes = figma.currentPage.findAll(node => node.type == “COMPONENT”);
for (let i = 0; i < nodes.length; i++) {
const localnode = nodes[i];
}
Hi Carmen, you can get all visual properties of any node including styles in geometry-related properties: ComponentNode · Figma Developers. Specifically, if you would need to get fill style, you can use let styleId = node.fillStyleId and then import this style by ID using let styleObject = figma.getStyleById(styleId) (figma · Figma Developers).
However, if you don’t need the style itself (its properties like name etc.) and you need only its properties (color, opacity, blend mode), you can get the fills array on the node and check which properties it has.
Hi I faced this problem recently and I finally solved it by reading Figma’s document. This error occurs because if you use this code the plugin will crash as if no elements in project weren’t selected by users. the only thing you have to do is adding two conditions to check this matter and avoid to crash.
if (!selection) {
return;
}
if (selection.type !== ‘FRAME’) {
return;
}