figma_eval
Run JavaScript directly inside the open Figma file with full plugin API access to read, modify, and return data, solving the need for custom automations and precise design operations without leaving the editor.
Instructions
Run JavaScript inside the Figma plugin sandbox, against the file where the bridge plugin is running.
The code body is wrapped in an async function: top-level await and return both work.
Globals: figma (full Plugin API) and helpers.
Use figma.getNodeByIdAsync(id) — the sync getNodeById is unavailable under dynamic-page access.
Switch pages with: await figma.setCurrentPageAsync(page)
Load fonts before ANY text mutation, or use helpers.setText / helpers.loadNodeFonts.
The return value is JSON-serialized (figma.mixed -> "mixed", cycles pruned). Real Figma nodes collapse to {id,name,type}; return plain data (ids, numbers, strings) instead.
resize() RESETS sizing: on TEXT it sets textAutoResize to NONE (resize first, then set textAutoResize = "HEIGHT"); on auto-layout frames it sets both sizing modes to FIXED (set them after resizing, or use helpers.set / helpers.createText, which order this correctly).
Heights of text and hug-sized frames read back correctly right after the change — if you see h=10 on a text you resized, the auto-resize was reset (see above).
Each mutating tool call becomes ONE undo step for the person (checkpointed with figma.commitUndo); figma_history {action:"undo"} reverts the last call if asked within 60 s. Call helpers.reveal(nodes) at the end so what you built is on their screen.
For structure + styles (fills, fonts, effects, auto-layout, bound variables, components) of an existing frame, prefer figma_metadata with styles:true over a hand-written walker; figma_tokens lists the file's variable collections and styles.
helpers: setText(node, chars), loadNodeFonts(node), createText({characters, font:{family,style}, fontSize, color:"#hex", width, lineHeight(%), letterSpacing(px), textCase, textAlign, name, parent, x, y}), rgb("#hex"), set(node, props), query(root, selector), createAutoLayout(dir, props), reveal(nodes), notify(msg), rgba("#hex8"), collection(name, [modes]), token(collection, name, "COLOR"|"FLOAT"|"STRING"|"BOOLEAN", value | {mode: value}), bind(node, "fills"|"strokes"|prop, variable), importComponent(key), instance(key, parent, props), command(kind, payload) — runs a typed command (tokens, metadata, find, changes...) from inside eval and returns {result}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript to run. Use return to send data back. | |
| timeoutMs | No | Default 60000. |