I have an Operator
defined as ImportImageOperator
which calls another operator thatTraceAlphaOperator
but it does not trigger showing the Adjust Last Operation panel for the latter operator. But if I want to have controlled by adjustable parametersdirectly 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. It uses openCVInitially I had everything in one operator but that did not seem to load an image and then traceswork due to the alpha channel ofimport dialog that image to create polygonswas in the way. So I can get itdecided to mostly work, but I don't see Adjust Last Operation panelsplit the operation into those two aforementioned operators. Here'sThis is the class definitionscript:
import bpy
class Import_Image_With_AlphaTraceAlphaOperator(bpy.types.Operator):
"""Import an image with an alpha channel and trace the outline"""
bl_idname = "object.import_and_trace_alpha"trace_alpha"
bl_label = "Import and trace"Trace alpha"
bl_options = {'REGISTER', 'UNDO'}
filepath:# bpy.props.StringProperty(subtype="FILE_PATH")'INTERNAL'}
expansion_pixelsthreshold: bpy.props.IntPropertyFloatProperty(
name = "expansion_pixels"name="Threshold",
description = "expand border (px)"default=1.0,
default = 12
)
alpha_threshold: bpy.props.FloatProperty(
name = "alpha_threshold",
description = "Alphadef threshold"execute(self,
default = 1
context)
epsilon: bpy.props.FloatProperty(
name =print("Execute "epsilon",TraceAlphaOperator")
description =# "accuracy",
do stuff like tracing the alpha
default = 0.001
return ){'FINISHED'}
defclass invokeImportImageOperator(self, context, eventbpy.types.Operator):
bl_idname = context.window_manager"object.fileselect_add(self)import_image_and_trace"
bl_label = "Import print(self.filepath)
image and trace alpha"
bl_options return= {'RUNNING_MODAL''REGISTER', 'UNDO'}
def execute(self, context):
# trace the alpha channel with openCV
image_data = trace_alphaprint(self.filepath, self.expansion_pixels, self.alpha_threshold,"Execute self.epsilonImportImageOperator")
# sort out the hierarchy of outlines returned by openCV
outlines = outer_contours(image_data)
do stuff #like loadsave theloaded image and createfurther aprocessing shader...
imageresult = bpy.data.imagesops.load(selfobject.filepath)
material = create_materialtrace_alpha(image'INVOKE_DEFAULT')
for outline inreturn outlines:result
# create the blender objects
outerPoly =def create_blender_polygoninvoke(outlineself, 1.0context, event):
apply_materialcontext.window_manager.fileselect_add(outerPoly, materialself)
return {"FINISHED"'RUNNING_MODAL'}
def menu_func(self, context):
self.layout.operator(Import_Image_With_Alpha.bl_idname)
def register():
install_modules()
bpy.utils.register_class(Import_Image_With_AlphaImportImageOperator)
bpy.types.TOPBAR_MT_file_importutils.appendregister_class(menu_funcTraceAlphaOperator)
def unregister():
bpy.utils.unregister_class(Import_Image_With_AlphaImportImageOperator)
bpy.types.TOPBAR_MT_file_importutils.removeunregister_class(menu_funcTraceAlphaOperator)
if __name__ == "__main__":
register()
I've defined a few propertiesThe only workaround I know is to have two separate buttons for the two operators. First, likeI click one button to invoke expansion_pixelsImportImageOperator
to load the image, and then I click another button to invoke alpha_thresholdTraceAlphaOperator
to perform the alpha tracing, but I'm unsure why they don't appear withwhich 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?