# geometry-script

Adopt this skill: https://proskills.md/skills/other/carson-katri-geometry-script-skills-geometry-script

Page: https://proskills.md/skills/other/carson-katri-geometry-script-skills-geometry-script
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: skills/geometry-script/SKILL.md
size: 8002
upstream: https://github.com/carson-katri/geometry-script/blob/main/skills/geometry-script/SKILL.md

````text
---
name: geometry-script
description: Build and edit Blender node trees in Python with the Geometry Script add-on (`from geometry_script import *`, `@tree`; `geometry_script.shader` for `@shader`/`@material`/`@world`; `geometry_script.compositor` for `@compositor`). Use when asked to create, change, debug or inspect a geometry node tree, shader node group, material, world or compositor node group, procedurally generate geometry in Blender, or when a script uses geometry_script — whether through Blender's official MCP server (execute_blender_code) or headless Blender.
---

# Geometry Script

Geometry Script turns a decorated Python function into a Geometry Nodes group.
Every Blender node is a generated, typed function. The add-on checks your
input names, output names, enum values and link types, and its errors say what
to change. **Guess, run and fix from the error.** That is cheaper than reading
up front.

The repo root is two directories above this file. `tools/` and `api/` paths
below are relative to it.

## The loop

1. Write the script to a `.py` file, not an inline string, so later edits are small diffs.
2. Run it and read the short report. Always go through `agent.run`: raw `exec` of
   the same script returns a traceback about 10x longer.
   - **Blender MCP, running Blender:** `execute_blender_code` with
     `from geometry_script import agent; agent.run("/abs/path/script.py", object="Name")`.
     The report comes back as `stdout`.
   - **Blender MCP, no window:** `execute_blender_code_for_cli` with a `blend_file` and
     `from geometry_script import agent; result = agent.run("/abs/path/script.py", object="Name", echo=False)`.
     This tool returns only `result`, not printed output.
   - **No MCP:** `python3 tools/run.py script.py --object Name`
     (add `--blend file.blend` to start from a file).
3. Fix the single error it prints, then run again.
4. Check the result with the report's geometry stats (vertex/face/point/instance
   counts, bounds) and node warnings. Take a viewport screenshot only when what
   it *looks like* matters.

**Live edit:** if the user has the script open in Blender's Text Editor with
Live Edit and the add-on's auto-resolve on, saving the file reruns it. Then
just edit the file and call `agent.status()`, which prints the latest run's report.

`agent.run` prints a few lines and returns them as `{"ok": bool, "report": str}`: each tree built (nodes, inputs, outputs), then the
evaluated geometry and node warnings for every object using those trees.
`object=` attaches the last tree built, or `tree=` if given, to that object,
creating the object if needed. Errors print as `ERROR Type: message` plus the
failing line of your script. Pass `traceback=True` only when that isn't enough.

## Saving context

| Need | Cheap way | Avoid |
|---|---|---|
| Find a node | `python3 tools/describe.py --search "points on faces"` or `agent.search(...)` | grepping `api/nodes.py` (9k+ lines) |
| A node's sockets | `python3 tools/describe.py set_position mesh_to_points` or `agent.describe(...)` | reading the generated function source |
| Shader / compositor nodes | `tools/describe.py --tree shader ...`, `agent.describe(..., tree="compositor")` | grepping `api/shader_nodes.py` / `api/compositor_nodes.py` |
| Check a build | `agent.run(...)` / `tools/run.py` report, or `agent.status()` after a live-edit save | raw `exec` with full tracebacks; screenshots |
| Understand an existing tree | `agent.describe_tree("Name")` (node group, material or world): prints it as Geometry Script calls, without default values | dumping `node_tree.nodes` / links |
| Know the API | this file | the book in `book/` (longer) |
| See the result | report stats first; then MCP `get_screenshot_of_area_as_image(area_ui_type="VIEW_3D", size_limit_in_bytes=200000)` | `get_screenshot_of_window_as_image` (the whole window) |
| A `bpy` (not node) question | MCP `search_api_docs` / `get_python_api_docs` | guessing, or long `dir()` dumps |

Describe only the nodes you're unsure of, and several in one call. Most names
are the node's UI name in snake_case, and the error will tell you if you're wrong.

## Writing trees

```python
from geometry_script import *

@tree("Scatter Cubes")                       # group name; rebuilt in place if it exists
def scatter_cubes(geometry: Geometry, count: int = 4, size: float = 0.3):
    mesh = grid(size_x=4.0, size_y=4.0, vertices_x=count, vertices_y=count).mesh
    points = mesh_to_points(mesh=mesh).points
    cube_mesh = cube(size=(size, size, size)).mesh     # socket tuples -> Combine XYZ
    lifted = set_position(geometry=points, offset=(0.0, 0.0, size * 2)).geometry
    return instance_on_points(points=lifted, instance=cube_mesh).instances
```

- **Inputs:** parameter annotations and defaults become group inputs: `Geometry`, `float`,
  `int`, `bool`, `str`, `Vector`, `Color`, `Rotation`, `Matrix`, `Menu`, `Object`,
  `Material`, `Collection`, `Image`, plus `Field[T]`, `Grid[T]`, `Vector2`. Return one
  value, a tuple, or a dict `{"Output Name": value}` for named outputs.
- **Node functions take keyword arguments only** and return a namedtuple of outputs:
  `mesh_to_points(mesh=m).points`. Enum settings are strings: `mode="FACES"`.
  Type settings (`data_type`, `input_type`) are inferred from what you link, so
  set them only to override.
- **Arithmetic** (`+ - * / % **`, unary `-`) on float, int and vector sockets
  adds Math / Vector Math nodes. Comparisons (`< <= > >= == !=`) add a
  Compare node and give a boolean socket: `z > 0.5`, `index().index % 2 == 0`.
  Combine them with `boolean_math`, not `and`/`or`/`not` or `0 < x < 1`.
  Fields such as `position().position` and `index().index` are plain sockets.
- **Calling a `@tree` function inside another `@tree`** adds a group node. Those
  take positional arguments: `repeat_grid(geometry)`.
- **Builds are all-or-nothing:** if a build raises, the previous tree (and its
  modifier input values) is left untouched. Modifiers keep their input values
  across rebuilds.
- **Names that would shadow Python builtins get a trailing underscore:** `math_`
  (`math(...)` also works, and `math.pi` is still the math module), `id_`,
  `object_`, `string_`.

### Zones

```python
@repeat_zone
def climb(geometry: Geometry, step: float, iteration: int):   # `iteration` is the index
    return set_position(geometry=geometry, offset=(0.0, 0.0, step)).geometry, step * 2.0

@simulation_zone
def fall(geometry: Geometry, delta_time: float):
    return set_position(geometry=geometry, offset=(0.0, 0.0, -1.0)).geometry

@for_each_element(domain="POINT")
def per_point(index: int, radius: float):
    return ForEachResult(main={"scale": radius * 2.0},
                         generated=[{"geometry": uv_sphere(radius=radius).mesh}])

@closure_zone
def scale(x: float, factor: float = 2.0):
    return x * factor

@tree("Zones")
def zones(geometry: Geometry):
    climbed = climb(geometry, 1.0, iterations=4).geometry
    out = per_point(mesh_to_points(mesh=climbed).points, radius=0.25)
    value = scale.evaluate(scale(), 1.0, 3.0)
    return {"Geometry": fall(out.generated.geometry), "Value": value}
```

### Shaders, materials, worlds and the compositor

Each tree type has its own module of node functions; names like `normal`, `mix`
or `object_info` mean different nodes in each. A node used in the wrong tree
raises an error naming the module it belongs to.

```python
from geometry_script import *            # geometry nodes, @tree / @geometry
from geometry_script import shader as sh # @sh.shader, @sh.material, @sh.world
from geometry_script import compositor as comp

@sh.shader("Stripes")                    # shader node group: works like @tree
def stripes(color: Color = (0.9, 0.3, 0.1, 1.0), scale: float = 6.0):
    wave = sh.wave_texture(scale=scale)
    return sh.mix(data_type="RGBA", factor=wave.factor, a=color, b=(0, 0, 0, 1)).result

@sh.material("Striped")                  # no parameters; return the surface shader,
````

## File: README.md
upstream: https://github.com/carson-katri/geometry-script/blob/main/README.md

````text
![Geometry Script wordmark](book/src/images/wordmark.png)

A scripting API for Blender's Geometry Nodes, shaders and compositor:

<table>
<tbody>
<tr>

<td>

```python
from geometry_script import *

@tree("Repeat Grid")
def repeat_grid(geometry: Geometry, width: int = 3, height: int = 3):
    mesh = grid(
        size_x=width, size_y=height,
        vertices_x=width, vertices_y=height,
    ).mesh
    points = mesh_to_points(mesh=mesh).points
    return instance_on_points(points=points, instance=geometry).instances
```

</td>
<td>

![Generated node tree](book/src/images/example_generated_tree.png)

</td>
</tr>
</tbody>
</table>

## Installation
Geometry Script is a Blender extension and requires Blender 5.2 or newer.

Drag the box for your Blender version into Blender to install it:

<p>
<a href="https://github.com/carson-katri/geometry-script/releases/download/nightly/geometry_script-1.0.0-blender-5.2.zip?repository=./index.json&amp;blender_version_min=5.2.0&amp;blender_version_max=5.3.0"><picture><source media="(prefers-color-scheme: dark)" srcset="book/src/images/install/blender-5.2-dark.svg"><img alt="Geometry Script for Blender 5.2" src="book/src/images/install/blender-5.2-light.svg" width="200" height="72"></picture></a>
<a href="https://github.com/carson-katri/geometry-script/releases/download/nightly/geometry_script-1.0.0-blender-5.3.zip?repository=./index.json&amp;blender_version_min=5.3.0&amp;blender_version_max=5.4.0"><picture><source media="(prefers-color-scheme: dark)" srcset="book/src/images/install/blender-5.3-dark.svg"><img alt="Geometry Script for Blender 5.3" src="book/src/images/install/blender-5.3-light.svg" width="200" height="72"></picture></a>
<a href="https://github.com/carson-katri/geometry-script/releases/download/nightly/geometry_script-1.0.0-blender-5.4.zip?repository=./index.json&amp;blender_version_min=5.4.0&amp;blender_version_max=5.5.0"><picture><source media="(prefers-color-scheme: dark)" srcset="book/src/images/install/blender-5.4-dark.svg"><img alt="Geometry Script for Blender 5.4" src="book/src/images/install/blender-5.4-light.svg" width="200" height="72"></picture></a>
</p>

Blender asks to allow online access if it's off, then to add the Geometry Script repository, then confirms the install. The [`nightly` release](https://github.com/carson-katri/geometry-script/releases/tag/nightly) always lists the links for every Blender version with a build.

To install manually instead:

1. Download the ZIP matching your Blender version from the [`nightly` release](https://github.com/carson-katri/geometry-script/releases/tag/nightly), e.g. `geometry_script-1.0.0-blender-5.2.zip`
2. Open *Blender* > *Preferences* > *Get Extensions*
3. Open the dropdown at the top right, choose *Install from Disk...* and select the downloaded ZIP file

### Claude Code skill
The repository is also a [Claude Code](https://claude.com/claude-code) plugin marketplace with a skill for building node trees with Geometry Script. Install it with:

```
/plugin install geometry-script --marketplace carson-katri/geometry-script
```

On Claude Code versions before 2.1.275, add the marketplace first:

```
/plugin marketplace add carson-katri/geometry-script
/plugin install geometry-script@geometry-script
```

The skill runs scripts through Blender's MCP server when it's connected, or in background Blender otherwise. Run `/plugin marketplace update geometry-script` to get the latest version, or turn on auto-update for the marketplace in `/plugin`.

## What is Geometry Script?
*Geometry Script* is a robust yet easy to use Python API for creating Geometry Nodes with code.

At a certain point, Geometry Node trees become unmanagably large. Creating node trees in Python enables quicker editing and reorganization of large, complex trees.

*Geometry Script* has all of the performance and capabilities of Geometry Nodes, but in a more managable format. The scripts are converted directly to Geometry Node trees making them easy to tweak for others unfamiliar with scripting.

Every node in your Blender version is available as a typed Python function, generated from Blender itself, so your editor can complete node names, inputs, outputs and enum values.

Shader node groups, materials, worlds and compositor node groups can be scripted the same way, with `geometry_script.shader` and `geometry_script.compositor`:

```python
from geometry_script.shader import *

@material("Gold")
def gold():
    return principled_bsdf(base_color=(1.0, 0.77, 0.34, 1.0), metallic=1.0, roughness=0.2).bsdf
```

## [Documentation](https://carson-katri.github.io/geometry-script/)
Read the documentation for more information on installation, syntax, and tutorials.

## Contributing
Use [`uv`](https://docs.astral.sh/uv/) to get `fake-bpy-module` and some pyright settings.

```sh
uv sync
```

The node modules (`api/nodes.py`, `api/shader_nodes.py` and `api/compositor_nodes.py`) are generated from Blender and aren't checked in. Loading the add-on from a checkout generates them with that Blender, or you can generate them yourself, e.g. for editor completions:

```sh
blender -b --factory-startup --python code_generator/node_functions_generator.py
```

To build an installable package for a specific Blender version, which generates the node modules with that Blender and runs the smoke test:

```sh
python tools/build.py --blender /path/to/blender  # writes dist/geometry_script-<version>-blender-<major>.<minor>.zip
```

Then you can [follow Blender's steps](https://developer.blender.org/docs/handbook/extensions/addon_dev_setup/#setting-up-project) to setup a symlink for a local repository.
````
