Is it possible to add a sub panel into a redo panel? If so, any kind of example, tutorial, link etc would be highly appreciated.
1 Answers
I can't imagine why my question has been downvoted, but anyway...
I wanted to add a sub panel into a redo panel, mainly for decorative purposes. As batFINGER said, this can't be done. So I made a fake sub panel with a label, an icon and a boolean.
Here is a code example of how I made it, if anyone wants to do something similar:
import bpy
class MYADDON_properties(bpy.types.PropertyGroup):
fold : bpy.props.BoolProperty(name="fold", default=0)
class MYADDON_PT_main_panel(bpy.types.Panel):
bl_idname = "myaddon.main_panel"
bl_label = "Fake Sub Panel for Redo Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "MYADDON"
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("MYADDON.operator")
class MYADDON_OT_operator(bpy.types.Operator):
bl_idname = "myaddon.operator"
bl_label = "Operator"
bl_description = "Operator"
bl_options = {'REGISTER','UNDO'}
def draw(self, context):
my_props = context.window_manager.myaddon_properties
layout = self.layout
row = layout.row()
row.split()
row.alignment = 'RIGHT'
if my_props.fold:
row.operator("MYADDON.unfold", text="", emboss=False, icon='DISCLOSURE_TRI_RIGHT')
else:
row.operator("MYADDON.fold", text="", emboss=False, icon='DISCLOSURE_TRI_DOWN')
row.alignment = 'LEFT'
row.label(text="Fake Sub Panel")
if not my_props.fold:
col = layout.column(align=True)
col.label(text="Label #1")
col.label(text="Label #2")
col.label(text="Label #3")
def execute(self, context):
return {"FINISHED"}
class MYADDON_OT_fold(bpy.types.Operator):
bl_idname = "myaddon.fold"
bl_label = ""
bl_description = ""
def execute(self, context):
my_props = context.window_manager.myaddon_properties
my_props.fold = True
return {"FINISHED"}
class MYADDON_OT_unfold(bpy.types.Operator):
bl_idname = "myaddon.unfold"
bl_label = ""
bl_description = ""
def execute(self, context):
my_props = context.window_manager.myaddon_properties
my_props.fold = False
return {"FINISHED"}
classes = (
MYADDON_properties,
MYADDON_OT_operator,
MYADDON_OT_fold,
MYADDON_OT_unfold,
MYADDON_PT_main_panel,
)
def register():
from bpy.utils import register_class
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.WindowManager.myaddon_properties = bpy.props.PointerProperty(type = MYADDON_properties)
def unregister():
from bpy.utils import unregister_class
for cls in classes:
unregister_class(cls)
del bpy.types.WindowManager.myaddon_properties
If someone has any kind of corrections or suggestions...
- 413
- 3
- 11
bpy.types.Operator), a subpanel requires a parent that is a panel (bpy.types.Panel) Can emulate a subpanel with conditionals in draw method, but it's not a real subpanel Way back commented here https://blender.stackexchange.com/questions/196824/how-can-i-make-a-dialog-window-make-changes-in-real-time#comment330059_196824 that perhaps using an operator approach for prefs was flawed and to consider making a prop group for this. Other issues have popped up re using the operator approach ie using the value of one in another – batFINGER Oct 29 '20 at 09:34