9
$\begingroup$

I'm using a script to show the User Preferences dialog:

bpy.ops.screen.userpref_show('INVOKE_DEFAULT')

But it shows the preferences "input" tab, and I want it to show the "Ad-ons" tab. I tried using this:

bpy.types.UserPreferences.active_section

It didn't work. How can I do that?

$\endgroup$
2
  • $\begingroup$ Could you please provide more details how you actually open the preference window? $\endgroup$ Commented Aug 22, 2021 at 10:21
  • $\begingroup$ Ok I found the command bpy.ops.screen.userpref_show() $\endgroup$ Commented Aug 22, 2021 at 10:26

2 Answers 2

8
$\begingroup$

You'd want to use

bpy.context.preferences.active_section = 'ADDONS'
$\endgroup$
0
4
$\begingroup$

I don't know if this is the correct way to do it, but I can tell you that it works.. Just put the name of your addon, as if you were using the search engine

bpy.ops.screen.userpref_show()
bpy.context.preferences.active_section = 'ADDONS'
bpy.data.window_managers["WinMan"].addon_search = "node wrangler"

If you want to open it, try the following code.

case 1 For Blender 3.2

addon_name = __name__.split(".")[0]
preferences = bpy.context.preferences
addon_prefs = preferences.addons[addon_name].preferences

bpy.ops.screen.userpref_show("INVOKE_DEFAULT")
addon_prefs.active_section = 'ADDONS'
bpy.ops.preferences.addon_expand(module = __name__.split(".")[0])
bpy.ops.preferences.addon_show(module = __name__.split(".")[0])

case 2 For Blender 3.2

bpy.ops.screen.userpref_show("INVOKE_DEFAULT")
bpy.context.preferences.active_section  = "ADDONS"
bpy.ops.preferences.addon_expand(module=__package__)
bpy.ops.preferences.addon_show(module=__package__)

Either will work.


When you want to run it somewhere other than under the package.

my_package/
├── __init__.py
└── my_subpackage/
    ├── my_submodule.py

init.py

addon_name = __name__.split(".")[0]

my_submodule.py

from my_package import addon_name

preferences = bpy.context.preferences
addon_prefs = preferences.addons[addon_name].preferences

bpy.ops.screen.userpref_show("INVOKE_DEFAULT")
addon_prefs.active_section = 'ADDONS'
bpy.ops.preferences.addon_expand(module = addon_name)
bpy.ops.preferences.addon_show(module = addon_name)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .