I'm learning how to create UI panels in Blender. I have an IntProperty that I want to specify a certain number of sub-panels for. So far I here:
import bpy, sys, imp
from bpy.types import Operator, Panel, PropertyGroup, Menu
from bpy.props import *
from bpy.utils import register_class, unregister_class
class OBJECTTOOL_Settings(PropertyGroup):
count: IntProperty(
name = "Count",
description="Number of objects to create",
default = 1,
min = 1,
max = 6
)
class OBJECTTOOL_PT_main_panel(Panel):
bl_label = "Object Tools"
bl_idname = "OBJECTTOOL_PT_main_panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Object Tools"
bl_context = "objectmode"
def draw(self, context):
layout = self.layout
scene = context.scene
objecttools = scene.objecttools
row = layout.row()
row.prop(objecttools, "count")
class OBJECTTOOL_PT_sub_panel(Panel):
bl_label = "Sub Panel"
bl_idname = "OBJECTTOOL_PT_sub_panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Object Tools"
bl_context = "objectmode"
bl_parent_id = "OBJECTTOOL_PT_main_panel"
def draw(self, context):
layout = self.layout
classes = (
OBJECTTOOL_Settings,
OBJECTTOOL_PT_main_panel,
OBJECTTOOL_PT_sub_panel
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
bpy.types.Scene.objecttools = PointerProperty(type=OBJECTTOOL_Settings)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
del bpy.types.Scene.objecttools
if name == "main":
register()
So of course the panel is being added by registering it, and it's being made a child by using the bl_parent_id tag.
How can I evaluate the value of the count: IntProperty I have setup, and have the same number of child panels created? I also want it to update the panels whenever the number changes.
(Eventually the plan is to have a menu in the sub panel that offers a menu of objects to create, then I can choose different objects in each panel, set parameters within the panel for that object, and then have a button at the top to create all objects according to the sub-panel selections.)

Would I need to dynamically register each of those too?
– DrewTNBD Jul 09 '20 at 09:22bpy.propsproperty definitions to a panel. (Wont work as expected). Dynamically registered panels posted as an example of how to make many based on one without a bunch of class defs that are mostly same. Not totally sure on what your aim is. Speculative note: A draw method can be defined on a property group. If still unclear perhaps post a new question linked back to this one for context. – batFINGER Jul 09 '20 at 12:31