Dragorn421
Dragorn421

Reputation: 184

Get bl_info/version of own addon

I want to access my addon version as stored in bl_info programatically, because I don't want to have duplicates of something that is meant to change.

I tried using addon_utils.addons_fake_modules, but that list is empty in background (--background command line argument) mode, which I'm interested in using.

I also tried from .__init__ import bl_info but results were inconsistent across Blender versions and with/without background mode.

Upvotes: 0

Views: 733

Answers (1)

Dragorn421
Dragorn421

Reputation: 184

Since importing __init__ caused issues for some reason, but importing other modules was fine, I made __init__ export the bl_info version itself.

In __init__.py:

def register():
    util.addon_version = bl_info['version']

In util.py:

def get_addon_version():
    # this is set in __init__
    return addon_version

Of course using util as a name isn't mandatory, nor is using a get_addon_version() getter function. I used a getter to make future changes easier.

Upvotes: 2

Related Questions