Blender extensions and scripting add-ons

I am adapting my add-ons to Blender extensions. The add-ons are enabled and mostly work correctly, but I am no longer able to access the add-ons from scripts. My main add-on is called import_daz. After it has been enabled, the script

import import_daz

still fails because the import_daz module is not found. Extensions end up in the 4.2/extensions/user_default directory, but Blender doesn’t seem add it to the python paths.

Another thing: I have read that the bl_info dict in __init__.py should be removed, but when I do I cannot enable the add-on.

The source could can be found at https://bitbucket.org/Diffeomorphic/import_daz/src.

Have you seen the long discussion about teh “proper” inclusion of addon and python packages on:

the the “spin-off”

??

2 Likes

Thank you for this. I managed to import the module into a sister module at the same level, using

import ..import_daz

instead of

import import_daz

Or in a version-independent way:

if bpy.app.version < (4,2,0):
    import import_daz
else:
    import ..import_daz

That solves my most pressing concern. However, the original problem how to import the module into a script remains, especially if the blend file isn’t saved so the __package__ variable is not set.

1 Like

Nice…

Wasn’t recognizing this in the devtalk thread yet. So i even learnt something more today :smile_cat:

1 Like

Where exactly are you trying to import this? You can likely use a relative import the same way you’ve done above. Can you provide more detail?