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?
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?
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$