Hello, Figma community!
I am working on a Figma plugin that needs to access the modes of both local and external library variable collections. However, I have encountered an issue where I am unable to access the modes of external libraries through the Figma Plugin API.
Here is the code I am using:
figma.on("selectionchange", async () => {
console.log("Selection changed!");
const selectedNodes = figma.currentPage.selection;
if (selectedNodes.length > 0) {
// Accessing modes for local variable collections
const localVariableCollections = figma.variables.getLocalVariableCollections();
localVariableCollections.forEach((collection) => {
console.log("Local collection name:", collection.name);
if (collection.modes) {
collection.modes.forEach((mode) => {
console.log("Mode:", mode.name);
});
}
});
// Accessing modes for external libraries
const libraryCollections =
await figma.teamLibrary.getAvailableLibraryVariableCollectionsAsync();
libraryCollections.forEach((collection) => {
console.log("Library collection name:", collection.name);
if (collection.modes) {
collection.modes.forEach((mode) => {
console.log("Mode:", mode.name);
});
}
});
}
});
Here are the logs from running the code:
Selection changed!
Local collection name: semantic colors
Mode: light
Mode: dark
Library collection name: Collection 1
Library collection name: Collection 2
As you can see, I am able to retrieve the modes for the local collection “semantic colors” (light and dark), but not for the external libraries “Collection 1” and “Collection 2”.
Is this a limitation of the Figma Plugin API, or am I missing something? If anyone has a solution or workaround to access the modes of external library variable collections, I would greatly appreciate it.
Thank you for your help!