2
$\begingroup$

Assuming that the bl_category has a name, and is listed together with "Tool" "View" "Item", which are natively exposed in blender in the bl_space_type = "VIEW_3D" Is it possible to have a list of all the applications that are exhibited in this space? And is it possible to change the currently active tab via a script?

$\endgroup$

1 Answer 1

5
$\begingroup$

Search registered classes.

To get all the classes in bpy.types that are a subclass of bpy.types.Panel and bl_space_type == 'VIEW_3D'

>>> for p in dir(bpy.types):
...     cls = getattr(bpy.types, p)
...     if (issubclass(cls, bpy.types.Panel)
...         and getattr(cls, "bl_space_type", "") == 'VIEW_3D'):
...             p, getattr(cls, "bl_category", "No Category")
...             
('CYCLES_VIEW3D_PT_shading_lighting', 'No Category')
('CYCLES_VIEW3D_PT_shading_render_pass', 'No Category')
('TOPBAR_PT_annotation_layers', 'No Category')
('TOPBAR_PT_gpencil_layers', 'No Category')
('TOPBAR_PT_gpencil_materials', 'No Category')
('TOPBAR_PT_gpencil_primitive', 'No Category')
('TOPBAR_PT_tool_fallback', 'No Category')
('VIEW3D_PT_active_tool', 'Tool')
('VIEW3D_PT_active_tool_duplicate', 'Tool')
('VIEW3D_PT_annotation_onion', 'View')
('VIEW3D_PT_collections', 'View')
('VIEW3D_PT_context_properties', 'Item')
('VIEW3D_PT_gizmo_display', 'No Category')
('VIEW3D_PT_gpencil_draw_context_menu', 'No Category')

... and lots more

Ok, lets recategorize bpy.types.VIEW3D_PT_grease_pencil from "View" to "Foo"

Check if it's registered (should be since it is in bpy.types, unregister it, change the category, re-register.

>>> cls = getattr(bpy.types, "VIEW3D_PT_grease_pencil")
>>> if cls.is_registered:
...     cls.bl_category
...     bpy.utils.unregister_class(cls)
...     cls.bl_category = "Foo"
...     bpy.utils.register_class(cls)
...     
'View'

enter image description here

Note this "trick" is used in some addons as an update on an addon preferences string property to recategorize panels

Inspect the module.

Similarly, since a lot of these are from bl_ui.space_view3d can inspect the module

>>> import importlib, inspect

>>> for name, cls in inspect.getmembers(importlib.import_module("bl_ui.space_view3d"), inspect.isclass):
...     if name.startswith('VIEW3D_PT'):
...         name, getattr(cls, "bl_category", "No Category")
...         
('VIEW3D_PT_active_tool', 'Tool')
('VIEW3D_PT_active_tool_duplicate', 'Tool')
('VIEW3D_PT_annotation_onion', 'View')
('VIEW3D_PT_collections', 'View')
('VIEW3D_PT_context_properties', 'Item')
('VIEW3D_PT_gizmo_display', 'No Category')
('VIEW3D_PT_gpencil_draw_context_menu', 'No Category')
... and many more

be remiss not to mention, most blender modules that register classes, have a classes list or tuple

from bl_ui.space_view3d import classes

for cls in classes:
     ... as above

or for every addon ... addon_utils.modules() provides a list of addon modules, that can be inspected as above to look for more, that may not even be enabled / registered.

AFAIK it's not possible to set the active panel / category (tab)

$\endgroup$

You must log in to answer this question.

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