https://github.com/SuperFLEB/blender-addon-template
This is a starting template for making Blender 4.5+ extension projects that includes a basic structure and a few tricks and code snippets. It evolves as I muddle my way through. They might not all be best practices, but they're mine.
- Blender 4.5+ extension structure with a
blender_manifest.tomlfile and wheels and all that. - Directories for library files (simple modules with collections of functions)
- An
__init__.pyandlib/addon.pywith register/deregister functions...- Class registration via list
- The ability to register whole modules that include a
REGISTER_CLASSESarray of their own - A common menu-item loader for both operators and submenus
- A subclass for no-draw() simplified submenus
- Support for a
can_show()static method on operators. Likepoll(), but hides the item instead of graying it out.- Note that the
can_show()method needs to be tested in menu and submenudraw()functions. It is not built in to Blender itself likepoll()is. The check is included in the sample submenu and the__init__.jsfile.
- Note that the
- A
utillib with some handy functions:- Flatten lists!
- Wrap words!
- Get the collections that objects are in!
- Get operators' defaults! And reset operators' properties to defaults!
- Example code:
- A starter Readme
- A simple operator that doesn't do much
- An operator with a whole bunch of panel components
- An operator with a UIList, including sorting and filtering
- A Preferences panel
- An Operator panel sub-panel
- A Properties panel (N panel)
- A submenu
- A packager, build_release.py
- Uses the Blender extension builder to package up the addon, plus:
- ...allows adding extra files from the root directory, such as README and licenses
- ...automatically downloads wheels, bundles them into a directory, and adds them to the blender_manifest.toml
- Packs up
src, and throws in whatever else you want - Uses Git v0.0.0-... semver tags to set the version number
- Uses the Blender extension builder to package up the addon, plus:
...and (if I forgot to update this Readme) so much more!
- Make a Python script to do the setup, instead of a bunch of search/replace
- Some libs for/examples of loading external data
- Simple, and clean-up-after-yourself loading
- Test examples (There used to be some, but they were removed because they didn't work with Blender)
- Do all the Git stuff:
- Clone it
- Make it yours! Remove the
.gitdirectory, andgit initto make a new project.
- In your IDE/editor of choice, do a few global replaces:
You'll also probably want to rename some of the class and parameter names in the operators if you use them as a base.
untitled_blender_addon -> Operator prefix and some file naming UntitledBlenderAddon -> Class/variable name prefix UNTITLED_BLENDER_ADDON -> bl_idname prefix Simple Operator -> The name for the simple operator UIList Operator -> The name for the UIList demo operator Untitled Blender Addon -> The full name of the addon Description goes here -> Descriptions Name goes here -> Your name {USERNAME}/{REPONAME} -> The GitHub info for this repo - Swap in the following files:
README.md(README.SAMPLE.md)LICENSE(LICENSE.(type).SAMPLE)CONTRIBUTING.md(CONTRIBUTING.SAMPLE.md)
- Start making your Blender addon!
build_release.py is a script that will package up your src directory, plus some other files, and make a ZIP archive,
ready to install. It's easily customizable and comes out-of-the-box ready to handle most projects built off this template.
- You'll need Python and Blender installed.
- Install the necessary dependencies for the builder script:
pip install -r requirements.txt - Copy the
.env.examplefile to.envand enter the path to your Blender executable. - Before building a release, you should update the
versionin yourblender_manifest.toml, then Git tag the latest commit to that version number (using "vX.X.X" format).Builds that do not have a version tag will be set to a version of "..<patch+1>-dev-" temporarily for the build.git tag v0.1.2
Then, simply run
python build_release.pyand a Blender-installable ZIP file will be generated.