Hello,
My code will refresh the first text box with the updated variable… but then it exits and throws runtime errors.
async function refreshNodesUsingVariables(updatedVariableIds) {
const nodes = Figma.currentPage.findAll();
for (const node of nodes) {
try {
let nodeUpdated = false;
if (node.boundVariables) {
for (const variableId of updatedVariableIds) {
for (const [property, boundVariable] of Object.entries(node.boundVariables)) {
if (boundVariable.id === variableId) {
if (typeof node.setVariableValue === 'function') {
node.setVariableValue(property, boundVariable);
} else {
console.warn(`Function 'setVariableValue' is not available on node ${node.name}`);
}
nodeUpdated = true;
}
}
}
}
if (nodeUpdated && node.type === 'TEXT' && node.fontName) {
try {
await figma.loadFontAsync(node.fontName);
node.characters = node.characters; // Refresh text node
} catch (fontError) {
console.warn(`Error loading font for node ${node.name}:`, fontError);
}
}
if (nodeUpdated) {
console.log(`Refreshed node: ${node.name} (${node.type})`);
}
} catch (error) {
console.warn(`Error updating node ${node.name} of type ${node.type}:`, error);
}
}
}
Errors:
Variable ELEC_SERV_NOTE updated successfully with value: T1-Note
Function ‘setVariableValue’ is not available on node T1-Type
Refreshed node: T1-Type (TEXT)
RuntimeError: null function or function signature mismatch
How it works:
It will actually refresh the first variable but none of the other ones.
I am not a very good coder and can’t find the issue.
Thanks for your time.