Why can't we display Operator properties within a Panel?

Hello

Basic question:

why python users aren’t allowed to display operators properties within a panel for example ?

we can pass the args via the UI but we can’t display and interact with them within the UI, why so ?

any trick in the book to do so ? witouth generating another Group of Properties elsewhere ofc

1 Like

You can, but you’d need to define the callback for the operator properties’ update function. Just have the callback call bpy.ops.undo_redo()

import bpy

def redo(self, context):
    if not redo.block:
        bpy.ops.ed.undo_redo()


class VIEW3D_PT_custom_redo_panel(bpy.types.Panel):
    bl_label = "Custom Redo Panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Tool"

    def draw(self, context):
        op = context.active_operator
        if op and op.bl_idname == "OBJECT_OT_simple_operator":
            layout = self.layout
            col = layout.column()
            for prop in op.properties.keys():
                col.prop(op.properties, prop)


class OBJECT_OT_simple_operator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}

    location: bpy.props.FloatVectorProperty(update=redo, size=3)
    hidden: bpy.props.BoolProperty(update=redo)

    def execute(self, context):
        context.object.location = self.location
        context.object.hide_set(self.hidden)
        return {'FINISHED'}

    def invoke(self, context, event):
        # Block the initial callback.
        redo.block = True
        self.location = context.object.location
        self.hidden = not context.object.visible_get()
        redo.block = False
        return self.execute(context)

if __name__ == "__main__":
    bpy.utils.register_class(VIEW3D_PT_custom_redo_panel)
    bpy.utils.register_class(OBJECT_OT_simple_operator)

4 Likes

thanks for the answer

yes but impossible to do so for non active operator right ?

for example: let the user define the parameters in the UI using the operator properties (and only thoses) then clicking on execute

This could be so handy

That’s even easier. Just use the keymap item’s operator properties :stuck_out_tongue:

import bpy

def execute_func(self, context):
    context.object.location = self.location
    context.object.hide_set(self.hidden)


class VIEW3D_PT_custom_redo_panel(bpy.types.Panel):
    bl_label = "Custom Redo Panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Tool"

    def draw(self, context):
        layout = self.layout
        col = layout.column()
        col.prop(kmi.properties, "location")
        col.prop(kmi.properties, "hidden")
        op = col.operator("object.simple_operator", text="Execute")
        op.location = kmi.properties.location
        op.hidden = kmi.properties.hidden


class OBJECT_OT_simple_operator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}

    location: bpy.props.FloatVectorProperty(size=3)
    hidden: bpy.props.BoolProperty()

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


if __name__ == "__main__":
    bpy.utils.register_class(VIEW3D_PT_custom_redo_panel)
    bpy.utils.register_class(OBJECT_OT_simple_operator)
    kmi = bpy.context.window_manager.keyconfigs.addon.keymaps['3D View'].keymap_items.new("object.simple_operator", "NONE", "ANY")
6 Likes

wow going trough a keymap to do so ? interresting !
thanks for the tip, i will investigate :face_with_monocle: