Skip to content

Hot-reload Blender addons during development

License

Notifications You must be signed in to change notification settings

razcore-rad/blender-addon-dev-watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

INFO

Tested with Blender 4.0.2.

Blender Addon Dev Watcher

This addon auto-reloads the watched addons when file changes get detected for a fast development cycle.

It uses the Python watchdog module.

The Problem

Blender addon development is greatly slowed down due to lack of hot-reloading on file changes.

Some proposed workarounds include:

  1. Refresh followed by disabling/enabling the addon from the Preferences... > Add-ons panel.
  2. Using the Reload Scripts button.

Both of these options are less than ideal.

The Solution

This addon found under the View 3D > Sidebar > Tool > Addon Dev Watcher panel lists the available (user) addons in the top list apart from itself.

We can add any addon from the top list to the bottom list with the Add Watch button. This starts a watchdog process waiting for file changes in the respective addon. When such a file change is detected it auto-reloads that addon.

To remove an addon from the watch list use the Remove Watch button.

That's it, nice and simple.

Notes

For now, there are no preference and the addon resets every time Blender is restart. This means that you have to actively add an addon to the watched list every restart.

The addon adds itself to the watch list and can't be unwatched. This is so we can hot-reload it during development at any time for whatever reason.

Refreshing the addon is done with the help of the bpy.ops.preferences.addon_disable(), bpy.ops.preferences.addon_enable() Blender function, and a solution to recursively reload modules from this gist.

The watchdog dependency is installed in the ADDON_PATH/dependnecies local folder by creating a virtual environment using the venv module.