0
$\begingroup$

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.

$\endgroup$
8
  • 2
    $\begingroup$ Even if you think that's a simple question, it's always harder getting into it for us without any sketch or example code. There are a lot possibilities as well as limitations as you might know by now. $\endgroup$
    – brockmann
    Oct 29, 2020 at 9:05
  • $\begingroup$ AFAIK the answer is no. The "redo panel" is an operator (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 blender.stackexchange.com/questions/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 $\endgroup$
    – batFINGER
    Oct 29, 2020 at 9:34
  • $\begingroup$ and here once again, another issue. My feeling is trying to use an operator redo panel for everything kinda makes you a A one trick pony down a rabbit hole Here is a recent answer re using the panel popover which in assoc with setting up pref property group would be perfect preferences blender.stackexchange.com/questions/197265/… $\endgroup$
    – batFINGER
    Oct 29, 2020 at 9:41
  • $\begingroup$ @batFINGER in other words your advice is not to use redo panel when have to make something like this? And that it would be better to work at the n panel for example? $\endgroup$ Oct 29, 2020 at 10:07
  • $\begingroup$ The linked image never loads for me. Advice is to consider it. IIRC I have mentioned also to look at code of add sapling addon that (last I looked) uses one monster redo panel. (All options available in one operator) A lot depends on what your addon does. Recommend finding an addon that does the same / similar and investigate the code. $\endgroup$
    – batFINGER
    Oct 29, 2020 at 10:33

1 Answer 1

0
$\begingroup$

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...

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .