Tuesday, July 9, 2019

Add-ons

This post was updated on July 24, 2019 due to changes in the add-on interface.

Recently user engetudouiti wrote a script for setting roll angles. Although the script appears to be useful, I have not studied it in detail and don't have time to support it.  Instead, I thought it might be a good idea to create a mechanism that lets users add functionality to the Daz importer. In short, an add-on system.

Blender of course already has an add-on system, and you could write Blender add-ons that invoke the import-daz module, but that approach has some drawbacks. In particular, such "horizontal" calling will break if the name of the import-daz module is changed, e.g. to diffeomorphic-import-daz-bb15d1ca5708. A cleaner solution would be that add-ons for the Daz importer could be handled by the importer itself. The new add-on system in the development version does just that. This is work in progress and details will almost certainly change in the near future.

A Daz importer add-on is a python file that you put in the addons directory (under the import-daz directory, which itself is located under Blender's addon directory). It must contain the same information as a Blender add-on: a bl_info dict, and a register and an unregister function. Packages are supported; in that case the file __init__.py, must contain the bl_info dict and the register and unregister functions.

The file __init__.py in the addons folder should not be touched. It is an empty file which is necessary to make the addons directory into a Python package.

Information about the add-ons is found in the new Add-Ons menu. When no add-ons are loaded, it only contains the buttons Refresh and Save Settings.
When we press Refresh a list of add-ons appear below the buttons. All add-ons are loaded into memory, but they are not yet registered.
The interface is very similar to Blender's native add-on interface, cf https://docs.blender.org/manual/en/latest/preferences/addons.html. Each add-on has an arrow button, an enable checkbox, and the name of the add-on. The arrow button displays more information about the add-on, which is extracted from the bl_info dict.

When the checkbox is enabled, the add-on's register function is executed.
The Save Settings button saves a list of enabled add-ons. The next time Blender is started (or when the F8 key is pressed), these add-ons are loaded and enabled.