adamearle / AniMix-Popout-Editor-Windows

Creating popout windows for Blender
9 stars 0 forks source link

# Dynamically get the list of Blender area types #16

Closed adamearle closed 1 year ago

adamearle commented 1 year ago

Dynamically get the list of Blender area types

import bpy import re

Try to set an invalid UI type to generate an error message

try: bpy.context.area.ui_type = '' except TypeError as e:

Extract the valid UI 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

Get the labels of the editor types

editor_labels = [bpy.types.Space.subclasses()[i].bl_rna.name for i in editor_types]

Print the editor types and their labels

for editor_type, editor_label in zip(editor_types, editor_labels): print(f'Editor Type: {editor_type}, Label: {editor_label}')