1
$\begingroup$

I want to draw undo props only when the shift is not pressed

import bpy
from bpy.types import Operator, Panel
from bpy.props import IntProperty


class XX_OT_Test(Operator):

    bl_label = 'Test'
    bl_idname = 'xx.test'
    bl_options = {'REGISTER', 'UNDO'}

    segments: IntProperty(
        name = 'Segments',
        description = 'Number of segments',
        min = 8, max = 16,
        default = 8,
    )

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True
        layout.use_property_decorate = False
        layout.prop(self, 'segments')

    def invoke(self, context, event):
        if event.shift:
            print('Invoke')
        else:
            self.execute(context)
        return {'FINISHED'}

    def execute(self, context):
        print('Execute')
        return {'FINISHED'}


class LayoutDemoPanel(Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "Layout Demo"
    bl_idname = "SCENE_PT_layout"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Test"

    def draw(self, context):
        layout = self.layout
        layout.operator("xx.test")


def register():
    bpy.utils.register_class(XX_OT_Test)
    bpy.utils.register_class(LayoutDemoPanel)
    


def unregister():
    bpy.utils.unregister_class(XX_OT_Test)
    bpy.utils.unregister_class(LayoutDemoPanel)
    

if __name__ == "__main__":
    register()
$\endgroup$

1 Answer 1

1
$\begingroup$

I don't think there is a non-hacky way to dynamically disable the redo panel. You can try using a flag that returns from draw early if you don't want the user messing with the settings.

import bpy
from bpy.types import Operator, Panel
from bpy.props import IntProperty


class XX_OT_Test(Operator):

    bl_label = 'Test'
    bl_idname = 'xx.test'
    bl_options = {'REGISTER', 'UNDO'}
    display_redo_settings = True

    segments: IntProperty(
        name = 'Segments',
        description = 'Number of segments',
        min = 8, max = 16,
        default = 8,
    )

    def draw(self, context):
        if not self.display_redo_settings:
            return
        layout = self.layout
        layout.use_property_split = True
        layout.use_property_decorate = False
        layout.prop(self, 'segments')

    def invoke(self, context, event):
        self.display_redo_settings = not event.shift
        self.execute(context)
        return {'FINISHED'}

    def execute(self, context):
        print('Execute')
        return {'FINISHED'}

Another method is super hacky and has some unintended consequences. You can dynamically change bl_options inside the invoke method.

def invoke(self, context, event):
    if event.shift:
        self.bl_options = {'REGISTER'}
    else:
        self.bl_options = {'REGISTER', 'UNDO'}
    self.execute(context)
    return {'FINISHED'}

After a bit of testing it seems using this with SHIFT enabled completely disables the redo panel for all operators so I wouldn't advise using it unless it's the only operator you're using.

$\endgroup$

You must log in to answer this question.

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