Skip to main content
added 1127 characters in body
Source Link
Noob Cat
  • 1.4k
  • 3
  • 25
  • 67

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)

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 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)
Source Link
Noob Cat
  • 1.4k
  • 3
  • 25
  • 67

How to get addon __name__ in another module into the same package or another subpackage?

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?