I have a multi-file/multi-folder add-on, with preferences properties created in a prefs.py.

import bpy

bl_idname = __package__

my_property : bpy.props.BoolProperty(
name = "my_bool",
)


I can easily access this bool in my __init__.py with:

bpy.context.preferences.addons[__package__].preferences.my_property


But I can't manage to access it in panel.py placed in a UI folder. What is the correct way to call that property in a multi-file add-on?

• I would guess those properties should be declared in a class, which is registered on blender startup? Mar 16 '20 at 1:46
• Yes I declare them in the init.py file: bpy.utils.register_class (prefs.AddonPreferences) But if I try to call them in my other files I get a KeyError: KeyError: 'bpy_prop_collection[key]: key "myaddon.ui.panel" not found' Mar 16 '20 at 2:01
• @chafouin What is the value of __package__ in prefs.py? Mar 16 '20 at 9:23
• @batFINGER Is it something I have to define manually? Mar 17 '20 at 1:03
• @batFINGER Printing it from the prefs.py returns the name of my top folder, which is the name of my addon (in that case, photographer) Mar 17 '20 at 3:51

My workaround was to have all the python files in a single folder and avoid subfolders. That way __package__ was returning the proper add-on name. This is not a real solution though.

I recently came across the same issue while developing an addon. I got a workaround from looking at this code of BlendLuxcore: use a mixture of basename and dirname from os.path to get to the folder name of your addon.

After observing how __init__.py packages everything together this simple trick worked. Please do let me know if some other correction is needed.

My folder structure:


The folder name (my_addon) should have pythonic name (no period, slash etc).

Now in __init__.py I put this simple import:

bl_info = {
"version": (3, 0),
"blender": (2, 90, 3),
"category": "Sequencer",
}

# this (from . import) go up one folder
#and will import the modules from that folder.
#As a result will recognize as a package.

from . import somefunc, anotherfunc
from .somefolder import otherfunc

modules = (somefunc, anotherfunc, otherfunc)

def register():
for m in modules:
m.register()

def unregister():
for m in modules:
m.unregister()

if __name__ == "__main__":
register()