I’ve seen a bunch of threads just like what I’m about ask so sorry for the repeat question. I’ve tried everything I read in the other threads and I still can’t create instances of the component in a file outside of the design library.
What I’m trying to achieve is based on the selection made it generates a specific component.
The file that I am linking to is a published design library and I have the key and the component set ID
However, I continue to get this error state in the console
unhandled promise rejection: Throw: Failed to import component set by key ""
figma.ui.onmessage = pluginMessage => {
const designLibraryFileId = 'key';
const componentSetId = 'ID';
figma.importComponentSetByKeyAsync(designLibraryFileId).then((componentSet) => {
const cartComponentSet = componentSet.findOne(node => node.type == "COMPONENT_SET" && node.name == "Cart Milestones") as ComponentSetNode;
const defaultVariant = cartComponentSet.defaultVariant as ComponentNode;
const m2Variant = cartComponentSet.findOne(node => node.type == "COMPONENT" && node.name == "Property 1=Cart M2") as ComponentNode;
const m3Variant = cartComponentSet.findOne(node => node.type == "COMPONENT" && node.name == "Property 1=Cart M3") as ComponentNode;
const m4Variant = cartComponentSet.findOne(node => node.type == "COMPONENT" && node.name == "Property 1=Cart M4") as ComponentNode;
const m5Variant = cartComponentSet.findOne(node => node.type == "COMPONENT" && node.name == "Property 1=Cart M5") as ComponentNode;
const m6Variant = cartComponentSet.findOne(node => node.type == "COMPONENT" && node.name == "Property 1=Cart M6") as ComponentNode;
if(pluginMessage.radioState === "cartM1"){
defaultVariant.createInstance();
} else if(pluginMessage.radioState === "cartM2"){
m2Variant.createInstance();
} else if(pluginMessage.radioState === "cartM3"){
m3Variant.createInstance();
} else if(pluginMessage.radioState === "cartM4"){
m4Variant.createInstance();
} else if(pluginMessage.radioState === "cartM5"){
m5Variant.createInstance();
} else if(pluginMessage.radioState === "cartM6"){
m6Variant.createInstance();
}
figma.closePlugin();
}
)}
Any help would be greatly appreciated.