Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/open-pencil/open-pencil/llms.txt

Use this file to discover all available pages before exploring further.

The eval command executes JavaScript code with access to the Figma plugin API (FigmaAPI). This provides programmatic access to all tools and operations.

Usage

bunx @open-pencil/cli eval <file> --code <javascript>

Arguments

file
string
required
Path to the .fig file

Options

--code
string
JavaScript code to execute
--stdin
boolean
Read code from stdin instead of --code flag
--write
boolean
Write changes back to the input file
--output
string
Write changes to a different file
--json
boolean
Output result as JSON
--quiet
boolean
Suppress output

Examples

Create a rectangle

bunx @open-pencil/cli eval design.fig --code '
  const rect = figma.createRectangle()
  rect.x = 100
  rect.y = 100
  rect.resize(200, 100)
  rect.fills = [{ type: "SOLID", color: { r: 1, g: 0, b: 0, a: 1 } }]
' --write

Query nodes

bunx @open-pencil/cli eval design.fig --code '
  const buttons = figma.currentPage.findAll(n => n.name.includes("Button"))
  return buttons.map(b => ({ id: b.id, name: b.name }))
' --json

Read code from stdin

cat script.js | bunx @open-pencil/cli eval design.fig --stdin --write

Modify multiple nodes

bunx @open-pencil/cli eval design.fig --code '
  const texts = figma.currentPage.findAll(n => n.type === "TEXT")
  for (const text of texts) {
    text.fontSize = 16
  }
' --output modified.fig

FigmaAPI access

The figma object provides access to the Figma plugin API:
  • figma.currentPage - Current page
  • figma.root - Document root
  • figma.createRectangle() - Create shapes
  • figma.createText() - Create text
  • figma.createFrame() - Create frames
  • figma.createComponent() - Create components
  • node.findAll(predicate) - Search nodes
  • node.remove() - Delete nodes
  • All other FigmaAPI methods
See FigmaAPI reference for the complete API.

Return values

The last expression or return statement is output:
# Returns selection count
bunx @open-pencil/cli eval design.fig --code '
  return figma.currentPage.selection.length
'
Objects with a toJSON() method are automatically serialized.

Writing changes

By default, eval does not modify the input file. Use --write or --output to persist changes:
  • --write - Overwrite the input file
  • --output path.fig - Write to a different file
--write overwrites the original file. Back up important files before using this flag.

Use cases

  • Batch updates to design tokens
  • Automated refactoring
  • Custom linting rules
  • Data-driven design generation
  • Integration with CI/CD pipelines

See also