adamearle / AniMix-Popout-Editor-Windows

Creating popout windows for Blender
9 stars 0 forks source link

Dynamically get the list of Blender modules types #15

Closed adamearle closed 1 year ago

adamearle commented 1 year ago

Dynamically get the list of Blender modules types

import bpy import re

Function to get modes of an editor type

def get_modes(editor_type):

Save the current editor type

current_editor_type = bpy.context.area.ui_type

# Set the context area's ui_type to the editor type
bpy.context.area.ui_type = editor_type

try:
    bpy.context.space_data.ui_mode = ''
except TypeError as e:
    # Extract the valid modes from the error message
    match = re.search(r'not found in \((.*)\)', str(e))
    if match:
        modes = match.group(1).split(', ')
        modes = [mode.strip("'") for mode in modes]
    else:
        raise e

# Restore the current editor type
bpy.context.area.ui_type = current_editor_type

return modes

Function to get editor types

def get_editor_types(): try: bpy.context.area.ui_type = '' except TypeError as e:

Extract the valid editor types from the error message

    match = re.search(r'not found in \((.*)\)', str(e))
    if match:
        editor_types = match.group(1).split(', ')
        editor_types = [editor_type.strip("'") for editor_type in editor_types]
    else:
        raise e

return editor_types

Get a list of editor types

editor_types = get_editor_types()

Print editor types and their modes

for editor_type in editor_types: print(f"Editor Type: {editor_type}") modes = get_modes(editor_type) print(f"Modes: {modes}") print()