Loading...
Loading...
Compare original and translation side by side
use_figmareferences/skillNames: "figma-use"use_figmasearch_design_systemuse_figmareferences/use_figmaskillNames: "figma-use"search_design_systemreturnfigma.closePlugin()awaitreturn(async () => { ... })()figma.notify()getPluginData()setPluginData()use_figmagetSharedPluginData()setSharedPluginData()console.log()returnuse_figma{r: 1, g: 0, b: 0}await figma.loadFontAsync({family, style})await figma.setCurrentPageAsync(page)setBoundVariableForPaintcreateVariablelayoutSizingHorizontal/Vertical = 'FILL'parent.appendChild(child)'HUG'figma.currentPage.childrenuse_figmareturnreturn { createdNodeIds: [...], mutatedNodeIds: [...] }variable.scopesALL_SCOPES["FRAME_FILL", "SHAPE_FILL"]["TEXT_FILL"]["GAP"]awaitfigma.loadFontAsync(...)awaitfigma.setCurrentPageAsync(page)awaitFor detailed WRONG/CORRECT examples of each rule, see Gotchas & Common Mistakes.
returnfigma.closePlugin()awaitreturn(async () => { ... })()figma.notify()getPluginData()setPluginData()use_figmagetSharedPluginData()setSharedPluginData()console.log()returnuse_figma{r: 1, g: 0, b: 0}await figma.loadFontAsync({family, style})await figma.setCurrentPageAsync(page)setBoundVariableForPaintcreateVariablelayoutSizingHorizontal/Vertical = 'FILL'parent.appendChild(child)'HUG'figma.currentPage.childrenuse_figmareturnreturn { createdNodeIds: [...], mutatedNodeIds: [...] }variable.scopesALL_SCOPES["FRAME_FILL", "SHAPE_FILL"]["TEXT_FILL"]["GAP"]awaitawaitfigma.loadFontAsync(...)awaitfigma.setCurrentPageAsync(page)每个规则的详细错误/正确示例,请见注意事项与常见错误。
use_figmafigma.currentPageuse_figmafigma.currentPageawait figma.setCurrentPageAsync(page)figma.currentPage = pageuse_figma// Switch to a specific page (loads its content)
const targetPage = figma.root.children.find((p) => p.name === "My Page");
await figma.setCurrentPageAsync(targetPage);
// targetPage.children is now populated
// Iterate over all pages
for (const page of figma.root.children) {
await figma.setCurrentPageAsync(page);
// page.children is now loaded — read or modify them here
}await figma.setCurrentPageAsync(page)figma.currentPage = pageuse_figma// 切换到指定页面(加载其内容)
const targetPage = figma.root.children.find((p) => p.name === "My Page");
await figma.setCurrentPageAsync(targetPage);
// 现在targetPage.children已加载完成
// 遍历所有页面
for (const page of figma.root.children) {
await figma.setCurrentPageAsync(page);
// page.children已加载——在此处读取或修改它们
}figma.currentPageuse_figmaawait figma.setCurrentPageAsync(page)use_figmareturnuse_figmafigma.currentPageawait figma.setCurrentPageAsync(page)use_figmareturnreturnreturnreturnreturn { createdNodeIds: [...], mutatedNodeIds: [...] }return { createdNodeIds: [...], count: 5, errors: [] }throwconsole.log()returnreturn { createdNodeIds: [...], mutatedNodeIds: [...] }return { createdNodeIds: [...], count: 5, errors: [] }throwconsole.log()use_figma"figma""figjam"use_figma"figma""figjam"use_figmause_figmause_figmareturnreturn { createdNodeIds: [...] }get_metadataget_screenshotuse_figmareturn { createdNodeIds: [...] }get_metadataget_screenshotStep 1: Inspect file — discover existing pages, components, variables, conventions
Step 2: Create tokens/variables (if needed)
→ validate with get_metadata
Step 3: Create individual components
→ validate with get_metadata + get_screenshot
Step 4: Compose layouts from component instances
→ validate with get_screenshot
Step 5: Final verification步骤1:检查文件——发现现有页面、组件、变量、命名约定
步骤2:创建令牌/变量(如果需要)
→ 使用get_metadata验证
步骤3:创建单个组件
→ 使用get_metadata + get_screenshot验证
步骤4:从组件实例组合布局
→ 使用get_screenshot验证
步骤5:最终验证| After... | Check with | Check with |
|---|---|---|
| Creating variables | Collection count, variable count, mode names | — |
| Creating components | Child count, variant names, property definitions | Variants visible, not collapsed, grid readable |
| Binding variables | Node properties reflect bindings | Colors/tokens resolved correctly |
| Composing layouts | Instance nodes have mainComponent, hierarchy correct | No cropped/clipped text, no overlapping elements, correct spacing |
| 操作后... | 使用 | 使用 |
|---|---|---|
| 创建变量 | 集合数量、变量数量、模式名称 | — |
| 创建组件 | 子节点数量、变体名称、属性定义 | 变体可见、未折叠、网格可读 |
| 绑定变量 | 节点属性反映绑定关系 | 颜色/令牌解析正确 |
| 组合布局 | 实例节点包含mainComponent、层级正确 | 文本无裁剪、元素无重叠、间距正确 |
use_figmause_figmause_figmause_figmaget_metadataget_screenshotget_metadataget_screenshot| Error message | Likely cause | How to fix |
|---|---|---|
| Used | Remove it — use |
| Set | Move |
| Used sync page setter | Use |
| Property value out of range | Color channel > 1 (used 0–255 instead of 0–1) | Divide by 255 |
| Node doesn't exist (wrong ID, wrong page) | Check page context, verify ID |
| Script hangs / no response | Infinite loop or unresolved promise | Check for |
| Parent instance was implicitly detached by a child | Re-discover nodes by traversal from a stable (non-instance) parent frame |
| 错误消息 | 可能原因 | 修复方法 |
|---|---|---|
| 使用了 | 删除它——使用 |
| 在追加到自动布局父节点前设置了 | 将 |
| 使用了同步页面设置器 | 使用 |
| 属性值超出范围 | 颜色通道值>1(使用了0–255而非0–1) | 将值除以255 |
| 节点不存在(错误的ID、错误的页面) | 检查页面上下文,验证ID |
| 脚本挂起/无响应 | 无限循环或未解决的Promise | 检查是否有 |
| 父实例被子节点的 | 从稳定的(非实例)父框架遍历重新发现节点 |
get_metadataget_screenshotFor the full validation workflow, see Validation & Error Recovery.
get_metadataget_screenshot完整的验证工作流,请见验证与错误恢复。
use_figmareturnfigma.closePlugin()returnfigma.notify()console.log()returnawait figma.setCurrentPageAsync(page)layoutSizingVertical/Horizontal = 'FILL'parent.appendChild(child)loadFontAsync()lineHeightletterSpacing{unit, value}resize()returnloadFontAsyncsetCurrentPageAsyncimportComponentByKeyAsyncawaituse_figmareturnfigma.closePlugin()figma.notify()console.log()returnawait figma.setCurrentPageAsync(page)layoutSizingVertical/Horizontal = 'FILL'parent.appendChild(child)loadFontAsync()lineHeightletterSpacing{unit, value}resize()loadFontAsyncsetCurrentPageAsyncimportComponentByKeyAsyncawaitconst pages = figma.root.children.map(p => `${p.name} id=${p.id} children=${p.children.length}`);
return pages.join('\n');const results = [];
for (const page of figma.root.children) {
await figma.setCurrentPageAsync(page);
page.findAll(n => {
if (n.type === 'COMPONENT' || n.type === 'COMPONENT_SET')
results.push(`[${page.name}] ${n.name} (${n.type}) id=${n.id}`);
return false;
});
}
return results.join('\n');const collections = await figma.variables.getLocalVariableCollectionsAsync();
const results = collections.map(c => ({
name: c.name, id: c.id,
varCount: c.variableIds.length,
modes: c.modes.map(m => m.name)
}));
return results;const pages = figma.root.children.map(p => `${p.name} id=${p.id} children=${p.children.length}`);
return pages.join('\n');const results = [];
for (const page of figma.root.children) {
await figma.setCurrentPageAsync(page);
page.findAll(n => {
if (n.type === 'COMPONENT' || n.type === 'COMPONENT_SET')
results.push(`[${page.name}] ${n.name} (${n.type}) id=${n.id}`);
return false;
});
}
return results.join('\n');const collections = await figma.variables.getLocalVariableCollectionsAsync();
const results = collections.map(c => ({
name: c.name, id: c.id,
varCount: c.variableIds.length,
modes: c.modes.map(m => m.name)
}));
return results;| Doc | When to load | What it covers |
|---|---|---|
| gotchas.md | Before any | Every known pitfall with WRONG/CORRECT code examples |
| common-patterns.md | Need working code examples | Script scaffolds: shapes, text, auto-layout, variables, components, multi-step workflows |
| plugin-api-patterns.md | Creating/editing nodes | Fills, strokes, Auto Layout, effects, grouping, cloning, styles |
| api-reference.md | Need exact API surface | Node creation, variables API, core properties, what works and what doesn't |
| validation-and-recovery.md | Multi-step writes or error recovery | |
| component-patterns.md | Creating components/variants | combineAsVariants, component properties, INSTANCE_SWAP, variant layout, discovering existing components, metadata traversal |
| variable-patterns.md | Creating/binding variables | Collections, modes, scopes, aliasing, binding patterns, discovering existing variables |
| text-style-patterns.md | Creating/applying text styles | Type ramps, font probing, listing styles, applying styles to nodes |
| effect-style-patterns.md | Creating/applying effect styles | Drop shadows, listing styles, applying styles to nodes |
| plugin-api-standalone.index.md | Need to understand the full API surface | Index of all types, methods, and properties in the Plugin API |
| plugin-api-standalone.d.ts | Need exact type signatures | Full typings file — grep for specific symbols, don't load all at once |
| 文档 | 加载时机 | 涵盖内容 |
|---|---|---|
| gotchas.md | 任何 | 所有已知陷阱及错误/正确代码示例 |
| common-patterns.md | 需要可用代码示例时 | 脚本模板:形状、文本、自动布局、变量、组件、多步骤工作流 |
| plugin-api-patterns.md | 创建/编辑节点时 | 填充、描边、自动布局、效果、分组、克隆、样式 |
| api-reference.md | 需要精确API接口时 | 节点创建、变量API、核心属性、支持与不支持的功能 |
| validation-and-recovery.md | 多步骤写入或错误恢复时 | |
| component-patterns.md | 创建组件/变体时 | combineAsVariants、组件属性、INSTANCE_SWAP、变体布局、发现现有组件、元数据遍历 |
| variable-patterns.md | 创建/绑定变量时 | 集合、模式、范围、别名、绑定模式、发现现有变量 |
| text-style-patterns.md | 创建/应用文本样式时 | 类型阶梯、字体探测、列出样式、将样式应用到节点 |
| effect-style-patterns.md | 创建/应用效果样式时 | 阴影、列出样式、将样式应用到节点 |
| plugin-api-standalone.index.md | 需要了解完整API接口时 | Plugin API中所有类型、方法和属性的索引 |
| plugin-api-standalone.d.ts | 需要精确类型签名时 | 完整类型定义文件——搜索特定符号,不要一次性全部加载 |