Metadata-Version: 2.4
Name: blendertk
Version: 0.28.3
Summary: Python toolkit for Blender mirroring mayatk's API: modeling, UV, materials, animation, rigging and export utilities.
Author-email: Ryan Simpson <m3trik@outlook.com>
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://github.com/m3trik/blendertk
Project-URL: Repository, https://github.com/m3trik/blendertk
Project-URL: Changelog, https://github.com/m3trik/blendertk/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/m3trik/blendertk/issues
Keywords: m3trik,blender,blender-python,bpy,rigging,technical-art,dcc
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Intended Audience :: Developers
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: COPYING
License-File: COPYING.EXCEPTION
Requires-Dist: pythontk>=0.27.3
Requires-Dist: uitk>=1.13.2
Dynamic: license-file

[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
[![PyPI](https://img.shields.io/pypi/v/blendertk.svg)](https://pypi.org/project/blendertk/)
[![Blender](https://img.shields.io/badge/Blender-4.x+-orange.svg)](https://www.blender.org/)
[![Tests](https://img.shields.io/badge/Tests-8110%20passed-brightgreen.svg)](../tests/)
![Platform](https://img.shields.io/badge/Platform-Windows%2C%20Linux-lightgrey.svg)

# blendertk

**mayatk's API, in Blender.** blendertk is the Blender library behind the [tentacle](https://github.com/m3trik/tentacle) toolset: the primitives and tools [mayatk](https://github.com/m3trik/mayatk) gives Maya, under the same names, on native `bpy` and `bmesh`.

<!-- diagram:ecosystem/blendertk -->
<!-- Generated by m3trik/scripts/generate_readme_diagrams.py from the workspace's declarations: change those and re-run it, never this block. -->
<p align="center">
<a href="https://github.com/m3trik/m3trik#readme"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/m3trik/m3trik/main/docs/diagrams/ecosystem-blendertk-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/m3trik/m3trik/main/docs/diagrams/ecosystem-blendertk-light.svg"><img alt="blendertk (highlighted) in the ecosystem: uitk requires pythontk; unitytk requires pythontk; mayatk requires uitk; blendertk requires uitk; tentacle requires uitk; extapps requires uitk; tentacle installs mayatk as its [maya] extra; tentacle installs blendertk as its [blender] extra; tentacle opens extapps by name (its [apps] extra) and never imports it; mayatk and blendertk share a mirrored API. tentacle and extapps are products, which nothing imports." src="https://raw.githubusercontent.com/m3trik/m3trik/main/docs/diagrams/ecosystem-blendertk-light.svg" width="781"></picture></a>
</p>
<!-- /diagram:ecosystem/blendertk -->

## Design

| Principle | In practice |
|:--|:--|
| **One API, two hosts** | Each operation carries mayatk's name, and its signature wherever a shared panel calls it, so one panel serves Maya and Blender with no branch. CI resolves every call those panels make against both libraries and fails on a gap. |
| **Thin where Blender is strong** | Where Blender ships a capability, blendertk is a thin layer over the `bpy` or `bmesh` operator. Where it does not, the logic is written once in [pythontk](https://github.com/m3trik/pythontk) and both host libraries bind it, so neither holds a second copy. |
| **Qt inside Blender** | Blender is not a Qt application: it runs no Qt event loop and bundles no binding. blendertk installs one on first launch, drives a `QApplication` from Blender's own timers and takes the activation key from Blender's keymap, so Qt panels and a marking menu work inside the viewport. |
| **One undo step per operation** | Blender has no call that opens and closes an undo group. `undo_chunk` suspends global undo for a block and pushes one step when it ends, so a compound operation is a single entry in Blender's history, and an edit that changed nothing adds none. |
| **Scenes cross both ways** | `MayaSceneImport` opens a `.ma` or `.mb` in Blender by converting it through a headless Maya; its USD route either keeps the scene's instancing exactly or fails and removes what it imported. Both hosts share one project file, Maya's `workspace.mel`. |
| **Measured speed** | Keys landed from an imported FBX are written in one bulk pass: 20 curves of 2,000 keys take 0.33 s instead of 59 s, bit-identical on whole frames. Planning a lightmap atlas before baking it made that bake 7.3 times faster. |
| **Imports without Blender** | Every `bpy` import is deferred into the call that uses it, so the whole API can be imported, searched and unit-tested with no Blender running. |
| **Test-driven, inside Blender** | Every bug is reproduced as a failing test before it is fixed, and the test stays in the suite. More than 8,000 checks run inside Blender itself, and a release requires a full passing run recorded against that exact source. |

The tools share mayatk's design (non-destructive exports, reversible baking, self-describing files): see [its README](https://github.com/m3trik/mayatk#design). The reasoning behind each rule is in the [code standard](https://github.com/m3trik/m3trik/blob/main/docs/CODE_STANDARD.md).

## What's in it

The subpackages, modules and class names are mayatk's; [STRUCTURE.md](STRUCTURE.md) maps what corresponds and what is deliberately absent on each side. A linked name opens that tool's readme.

| Package | What it holds |
|:--|:--|
| `anim_utils` | [Shot Manifest](https://github.com/m3trik/tentacle/blob/main/docs/tools/shot_manifest.md), [Shot Sequencer](https://github.com/m3trik/tentacle/blob/main/docs/tools/shot_sequencer.md), Smart Bake, key stash, blendshape animation, playblast, key scaling and staggering |
| `audio_utils` | Sound strips in the Video Sequence Editor |
| `cam_utils` | View capture and navigation, camera clipping, cameras from the current view, view state save and restore |
| `core_utils` | `CoreUtils`, `AutoInstancer`, `Preview`, script jobs over `bpy.app.handlers`, diagnostics |
| `display_utils` | Color ID, exploded view, `OutlinerTint` |
| `edit_utils` | `EditUtils`, mirror, cut on axis, duplicate (linear, radial, grid), bevel, bridge, snap, naming, curtain, target weld |
| `env_utils` | `BlenderConnection`, workspaces, reference manager, hierarchy sync, FBX and USD, [Scene Exporter](https://github.com/m3trik/tentacle/blob/main/docs/tools/scene_exporter.md), Maya and Unity bridges, WebXR preview, docked script console |
| `light_utils` | [Lightmap Baker](https://github.com/m3trik/tentacle/blob/main/docs/tools/lightmap_baker.md), [Light Rigs](https://github.com/m3trik/tentacle/blob/main/docs/tools/light_rig.md), HDR manager, lights from geometry |
| `mat_utils` | Game shader, material updater, texture path editor, shader templates, render effects, image to plane, [Emissive Groups](https://github.com/m3trik/tentacle/blob/main/docs/tools/emissive_groups.md), Marmoset and Substance bridges |
| `node_utils` | `NodeUtils`, [scene data nodes](data_nodes.md), the Channels engine |
| `nurbs_utils` | Curve helpers, `ImageTracer`, curve to tube |
| `render_utils` | Render engines, render settings and their presets, render cameras |
| `rig_utils` | Constraints, drivers and armature primitives; tube, wheel and telescope rigs, [Articulated Rig](https://github.com/m3trik/tentacle/blob/main/docs/tools/articulated_rig.md), [Shadow Rig](https://github.com/m3trik/tentacle/blob/main/docs/tools/shadow_rig.md) |
| `ui_utils` | `BlenderUiHandler`, the marking-menu host, native-menu wrapper, Qt dock container, calculator, style setter |
| `uv_utils` | Move, scale and pin UVs, texel density, UV set cleanup, [Texture Combine](https://github.com/m3trik/tentacle/blob/main/docs/tools/texture_combine.md), Rizom bridge |
| `xform_utils` | Freeze and restore transforms, pivots, alignment and placement, matrices |

To find any public name, search the installed source: `python -m pythontk ops run api.search "query=<words>"`. Over MCP, an agent gets the same search and runs its calls in a Blender started for it ([setup](https://github.com/m3trik/m3trik/blob/main/docs/AGENT_INSTRUCTIONS.md#elsewhere)). See also: [changelog](../CHANGELOG.md) · [tests](../tests/README.md) · [contributing](../AGENTS.md) · [issues](https://github.com/m3trik/blendertk/issues).

## Install

```bash
pip install blendertk
```

`bpy` comes from Blender itself; development runs against Blender 5.1 (Python 3.13). [tentacle's installer](https://github.com/m3trik/tentacle#install) installs it together with the panels.

This script runs in Maya with `mayatk` in place of `blendertk`:

```python
import blendertk as btk

@btk.CoreUtils.undoable                           # the whole call is one undo step
def freeze_groups(nodes):
    groups = btk.NodeUtils.is_group(nodes, filter=True)
    with btk.CoreUtils.preserved_selection():     # restores the selection afterwards
        btk.XformUtils.freeze_transforms(groups, translate=True, rotate=True, scale=True)
    return groups

groups = freeze_groups(["grp_a", "grp_b", "pCube1"])
btk.XformUtils.restore_transforms(groups)         # restores the values it zeroed
```

## License

GPL-3.0-or-later — see [COPYING](https://github.com/m3trik/blendertk/blob/main/COPYING), plus an additional permission to combine it with mayatk, tentacle and Autodesk Maya ([COPYING.EXCEPTION](https://github.com/m3trik/blendertk/blob/main/COPYING.EXCEPTION)).
