One can make a sub-panel to be drawn inside a parent panel using bpy.types.Panel.bl_parent_id.
import bpy
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Scene properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
self.layout.label(text="Hello world!", icon='WORLD_DATA')
class HelloWorldSubPanel(bpy.types.Panel):
"""Creates a Panel in the Scene properties window"""
bl_label = "Hello World Sub Panel"
bl_idname = "OBJECT_PT_sub_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_parent_id = "OBJECT_PT_hello"
bl_context = "scene"
def draw(self, context):
self.layout.label(text="Hello world!", icon='WORLD_DATA')
def register():
bpy.utils.register_class(HelloWorldPanel)
bpy.utils.register_class(HelloWorldSubPanel)
if name == "main":
register()
I can check if the two panels are related with :
print(HelloWorldSubPanel.bl_parent_id == HelloWorldPanel.bl_idname) # Returns True
But suppose I don't have access to the child class or don't want to hardcode the relationship test.
How would I know, without having access to the child panel class code, if the parent panel contains any children sub-panel ?
