I built some functions into python module functions.py
, but in it if I try to get the __name__
I get something like __name __.functions
How do you get the name of the addon a pythonic way?
I add some details:
Example module functions.py
def open_user_pref(context, addon_name):
preferences = context.preferences.addons[addon_name].preferences
bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
bpy.context.preferences.active_section = 'ADDONS'
bpy.ops.preferences.addon_expand(module=addon_name)
bpy.ops.preferences.addon_show(module=addon_name)
Example call from __init__.py
from . import functions
functions.open_user_pref(bpy.context, __name__)
But if I want to avoid the input name, I should find the exact name of the addon. So how can this be done?
def open_user_pref(contex):
#addon_name = __name__.split(".")[0] ? This seems dangerous to me if this package becomes a subpackage
preferences = context.preferences.addons[addon_name].preferences
bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
bpy.context.preferences.active_section = 'ADDONS'
bpy.ops.preferences.addon_expand(module=addon_name)
bpy.ops.preferences.addon_show(module=addon_name)
__name__
) will be the same as folder or python file name (without py extension) in theaddons
folder. Iffunctions.py
is a submodule of your addon, then it is not itself an addon. If so and you are getting the package name of functions as egmyaddon.functions
split on "." . $\endgroup$