2
$\begingroup$

I have an Operator defined as ImportImageOperator which calls another operator TraceAlphaOperator but it does not trigger showing the Adjust Last Operation panel for the latter operator. But if I directly call TraceAlphaOperator then it shows the panel. But why not when it is invoked by another operator?

enter image description here

I tried calling bpy.ops.object.trace_alpha(param) from the ImportImageOperator and testing it with both parameters EXEC_DEFAULT and INVOKE_DEFAULT, but nothing works. Initially I had everything in one operator but that did not seem to work due to the import dialog that was in the way. So I decided to split the operation into those two aforementioned operators. This is the script:

import bpy

class TraceAlphaOperator(bpy.types.Operator):
    bl_idname = "object.trace_alpha"
    bl_label = "Trace alpha"
    bl_options = {'REGISTER', 'UNDO'} # 'INTERNAL'}

    threshold: bpy.props.FloatProperty(
        name="Threshold",
        default=1.0,
    )

    def execute(self, context):
        print("Execute TraceAlphaOperator")
        # do stuff like tracing the alpha
        return {'FINISHED'}

class ImportImageOperator(bpy.types.Operator):
    bl_idname = "object.import_image_and_trace"
    bl_label = "Import image and trace alpha"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):
        print("Execute ImportImageOperator")
        # do stuff like save loaded image and further processing ...
        result = bpy.ops.object.trace_alpha('INVOKE_DEFAULT')
        return result

    def invoke(self, context, event):
        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}

def register():
    bpy.utils.register_class(ImportImageOperator)
    bpy.utils.register_class(TraceAlphaOperator)

def unregister():
    bpy.utils.unregister_class(ImportImageOperator)
    bpy.utils.unregister_class(TraceAlphaOperator)

if __name__ == "__main__":
    register()

The only workaround I know is to have two separate buttons for the two operators. First, I click one button to invoke ImportImageOperator to load the image, and then I click another button to invoke TraceAlphaOperator to perform the alpha tracing, which also displays the Adjust Last Operation panel. However, I would prefer pressing only one button to load and trace the alpha. Is this not possible?

$\endgroup$
6
  • 1
    $\begingroup$ It seems that the behavior to have adjustable parameters does not work if you have a dialog popup in between as tested when I removed the entire invoke function which then works. Can you not separate the operator that loads the image and then have another operator for the tracing? So your addon can have 1 button to load the image and then 1 button that will execute the tracing. That way you can show the Adjust Last Operation panel after you click the button to trace. $\endgroup$
    – Harry McKenzie
    Commented Jul 7 at 15:02
  • $\begingroup$ But I'm not 100% sure if it indeed is possible to have it as 1 operator. $\endgroup$
    – Harry McKenzie
    Commented Jul 7 at 15:04
  • 1
    $\begingroup$ Thanks for that, and the edit. You should convert this to an answer. $\endgroup$
    – stib
    Commented Jul 8 at 0:22
  • $\begingroup$ I did some simple test with one operator calling another operator and expecting the Adjust Last Operation panel to appear for the second operator but it's not working. So I'm interested in the answers to this question. Is it okay if I change your question's content to this simple scenario? $\endgroup$
    – Harry McKenzie
    Commented Jul 8 at 2:40
  • 1
    $\begingroup$ Yes, that's fine. $\endgroup$
    – stib
    Commented Jul 8 at 4:13

0

You must log in to answer this question.

Browse other questions tagged .