How packtpublishing/python-scripting-in-blender works
This repository is a chapter-by-chapter companion to a Blender Python scripting book. It is not a single application; it is a collection of independent examples that all run inside Blender’s Python environment and demonstrate progressively more capable scripting and add-on patterns.
The top-level structure is the main architectural clue: ch1 through ch12 each represent a learning stage, and each chapter contains one or more standalone scripts or add-on folders. There is no shared application runtime across chapters; each folder is a separate example boundary.
The core platform boundary is Blender itself. All meaningful code depends on bpy and Blender’s data model, context, operators, UI system, and add-on registration lifecycle. In other words, the repo’s “backend” is Blender’s scene/object system, not an external service or custom server.
Chapters 1–2 are introductory scripting examples. ch1/OurFirstScript.py is a basic script entry point, while ch2 focuses on accessing Blender modules, Blender data, and user context. Architecturally, these are one-off procedural scripts that read and mutate Blender state directly.
Chapters 3–5 move into simple add-ons and UI integration. Examples like the_simplest_add_on.py, object_collector.py, object_floor_transform.py, and very_simple_panel.py show the transition from script-only logic to registered add-ons with operators and panels. The important boundary here is between core action logic and Blender UI/registration hooks.
Chapter 6 is the clearest “mini-application” in the repo: structured_addon/ is a package with multiple modules. It separates responsibilities into operators.py, panel.py, objects_panel.py, preferences.py, img_loader.py, and package initialization in __init__.py. This is the repo’s main example of layered add-on architecture: shared package state, operator logic, UI panels, add-on preferences, and asset loading.
The structured_addon folder also contains pictures and a _refresh_.py helper, which suggests bundled UI/media assets and a reload/refresh workflow during development. This is a useful diagram boundary: code modules in one group, packaged resources in another.
Chapters 7–9 focus on event-driven and animation-related tools. Scripts such as action_to_range.py, vert_runner.py, object_shaker.py, and pendulum.py imply manipulation of animation data, object motion, and time-based behavior. These examples likely interact with Blender’s action/animation system and scene updates rather than just static object creation.
Chapter 8 includes _scenes_/ani_loop.blend, which is a sample Blender scene asset used as input data for the chapter’s automation or animation example. This introduces a data-file boundary separate from Python code: the scene file is loaded into Blender and then modified by scripts/add-ons.
Later chapters continue the pattern of self-contained tools. ch10/addons/punchclock.py, ch11/addons/latte_express.py, and ch12/addons/textament.py are each standalone add-ons, likely demonstrating more advanced event handling, UI, or content-generation workflows. Each sits under its own chapter rather than sharing a monolithic codebase.
The repository also contains chapter-local media assets, especially under ch12/_media_/textures and ch6/addons/structured_addon/pictures. These support the add-ons visually, so the architecture includes bundled assets alongside Python code rather than relying on external asset management.
From an architecture-diagram perspective, the key flow is: user action inside Blender UI or script execution → add-on/operator logic in Python → Blender API (bpy) → Blender scene/data/UI state. In some chapters, the flow also includes packaged chapter assets such as textures, images, or .blend files.
Tooling is intentionally minimal. The repo is designed to be opened in Blender 3.3 and edited in VS Code; there is no custom build system, service layer, or deployment pipeline. Installation/distribution concepts appear only in the context of Blender add-ons.
So the repository’s architecture is best understood as a set of isolated Blender example modules grouped by learning topic, with a progression from procedural scripts to registered add-ons, from direct data manipulation to UI-driven and animation-driven tools, and from single-file examples to a structured package with resources and preferences.
Main entry points: __init__.py Structured addon · operators.py Operators · object_shaker.py Object shaker · textament.py Textament
Components 22
Blender platform
The Blender runtime, data model, operators, UI, and add-on lifecycle that all examples target.
- Blender API · Blender’s Python environment, scene/object data, operators, UI, and registration APIs.
Early chapters
Introductory scripts and first add-on examples.
- First script · A basic entry-level Blender Python script.
ch1/OurFirstScript.py - Context basics · A small set of scripts showing Blender modules, data access, and user context.
ch2/0300_accessing_blender_modules.py
Add-on chapters
Chapters focused on operators, panels, and registered add-ons.
- Simple add-on · Early transition from script-only logic to a registered Blender add-on.
ch3/addons/object_collector.py - Addon start · The simplest add-on entry point used to introduce registration patterns.
ch3/the_simplest_add_on.py - Floor transform · An add-on example focused on object transformation logic.
ch4/addons/object_floor_transform.py - Simple panel · A minimal add-on that introduces Blender UI panels.
ch5/addons/very_simple_panel.py
Structured add-on
The chapter 6 package that splits an add-on into multiple modules and resources.
- Structured addon · The main multi-module add-on example with clear internal separation of concerns.
ch6/addons/structured_addon/__init__.py - Operators · Operator logic for the structured add-on.
ch6/addons/structured_addon/operators.py - Main panel · Primary UI panel for the structured add-on.
ch6/addons/structured_addon/panel.py - Objects panel · Secondary panel focused on object-related UI.
ch6/addons/structured_addon/objects_panel.py - Preferences · Add-on preferences and configuration state.
ch6/addons/structured_addon/preferences.py - Image loader · Asset-loading helper for bundled images.
ch6/addons/structured_addon/img_loader.py - Pictures · Packaged images used by the structured add-on.
ch6/addons/structured_addon/pictures
Motion chapters
Examples centered on animation, time-based behavior, and motion control.
- Animation tools · Animation- and motion-oriented add-ons and utilities.
ch7/addons/action_to_range.py - Object shaker · A time-based motion example that likely drives object movement and updates.
ch8/addons/object_shaker.py - Pendulum · An animation-oriented example using Blender motion and timing.
ch9/addons/pendulum.py
Later add-ons
Standalone add-ons in the final chapters.
- Punch clock · A standalone later-chapter add-on example.
ch10/addons/punchclock.py - Latte express · A later-chapter standalone add-on example.
ch11/addons/latte_express.py - Textament · A final-chapter add-on example with bundled media.
ch12/addons/textament.py
Chapter assets
Bundled scene and media files used by the examples.
- Loop scene · A sample Blender scene file used as chapter input data.
ch8/_scenes_/ani_loop.blend - Textures · Packaged texture assets supporting the final chapter add-on.
ch12/_media_/textures
Connections 24
- First script → Blender API: uses · Runs as a Blender script and directly mutates scene state.
- Context basics → Blender API: reads/writes · Demonstrates module access, data access, and user context inside Blender.
- Addon start → Blender API: registers with · Introduces add-on registration in Blender.
- Simple add-on → Blender API: operates on · Collects or manipulates objects through Blender data and operators.
- Floor transform → Blender API: operates on · Applies object transform logic through Blender APIs.
- Simple panel → Blender API: extends UI · Adds a Blender panel to expose add-on actions.
- Structured addon → Blender API: registers with · Package entry point integrates the structured add-on into Blender.
- Structured addon → Operators: loads · Initializes operator definitions as part of the package.
- Structured addon → Main panel: loads · Initializes the main UI panel module.
- Structured addon → Objects panel: loads · Initializes the object-specific UI module.
- Structured addon → Preferences: loads · Initializes add-on preferences.
- Structured addon → Image loader: loads · Initializes image-loading support.
- Image loader → Pictures: reads · Loads bundled pictures used by the add-on.
- Main panel → Operators: invokes · UI triggers operator actions.
- Objects panel → Operators: invokes · Object-focused UI triggers operators.
- Preferences → Blender API: configures · Uses Blender’s preference and registration mechanisms.
- Animation tools → Blender API: animates · Works with actions, ranges, and motion-related Blender data.
- Object shaker → Blender API: updates · Drives object motion over time in Blender.
- Object shaker → Loop scene: uses scene · Operates against the sample animation scene.
- Pendulum → Blender API: drives motion · Implements a pendulum-style animation example.
- Punch clock → Blender API: registers with · Standalone add-on example built for Blender.
- Latte express → Blender API: registers with · Standalone add-on example built for Blender.
- Textament → Blender API: registers with · Final add-on example built for Blender.
- Textament → Textures: uses · Relies on bundled texture/media assets.