Skip to content

Instantly share code, notes, and snippets.

@SuddenDevelopment
Created September 11, 2021 03:09
Show Gist options
  • Save SuddenDevelopment/9eca499bc3916e8fdb41d9d6c442c365 to your computer and use it in GitHub Desktop.
Save SuddenDevelopment/9eca499bc3916e8fdb41d9d6c442c365 to your computer and use it in GitHub Desktop.
Blender addon UI create collapsible subpanel
import bpy
class EXAMPLE_panel:
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Hi"
bl_options = {"DEFAULT_CLOSED"}
#The primary panel, no parents
class EXAMPLE_PT_panel_1(EXAMPLE_panel, bpy.types.Panel):
bl_idname = "EXAMPLE_PT_panel_1"
bl_label = "Main"
def draw(self, context):
pass
#subpanel only used as a grouping of child panels
class EXAMPLE_PT_panel_2(EXAMPLE_panel, bpy.types.Panel):
bl_parent_id = "EXAMPLE_PT_panel_1"
bl_label = "Subpanel"
def draw(self, context):
layout = self.layout
layout.label(text="Here there will be more stuff")
#child panel, without showing title
class EXAMPLE_PT_panel_3(EXAMPLE_panel, bpy.types.Panel):
bl_parent_id = "EXAMPLE_PT_panel_1"
bl_label = "(should not exist)"
bl_options = {'HIDE_HEADER'}
def draw(self, context):
column = self.layout.column(align = True)
column.operator("mesh.primitive_plane_add", text = "Plane")
classes = (EXAMPLE_PT_panel_1, EXAMPLE_PT_panel_2, EXAMPLE_PT_panel_3)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment