Skip to main content
Notice removed Authoritative reference needed by Harry McKenzie
Bounty Ended with X Y's answer chosen by Harry McKenzie
Notice added Authoritative reference needed by Harry McKenzie
Bounty Started worth 100 reputation by Harry McKenzie
edited tags
Link
quellenform
  • 39.5k
  • 10
  • 56
  • 149
added 62 characters in body; edited title
Source Link
Harry McKenzie
  • 14.5k
  • 11
  • 34
  • 74

Trouble setting up an Operator called by another operator withdoes not trigger Adjust Last Operation panel

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?

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

Trouble setting up an operator with Adjust Last Operation panel

I have an operator that I want to have controlled by adjustable parameters when it is invoked. It uses openCV to load an image and then traces the alpha channel of that image to create polygons. I can get it to mostly work, but I don't see Adjust Last Operation panel. Here's the class definition:

class Import_Image_With_Alpha(bpy.types.Operator):
    """Import an image with an alpha channel and trace the outline"""
    bl_idname = "object.import_and_trace_alpha"
    bl_label = "Import and trace alpha"
    bl_options = {'REGISTER', 'UNDO'}

    filepath: bpy.props.StringProperty(subtype="FILE_PATH")

    expansion_pixels: bpy.props.IntProperty(
        name = "expansion_pixels",
        description = "expand border (px)",
        default = 12
    )
    alpha_threshold: bpy.props.FloatProperty(
        name = "alpha_threshold",
        description = "Alpha threshold",
        default = 1
    )
    epsilon: bpy.props.FloatProperty(
        name = "epsilon",
        description = "accuracy",
        default = 0.001
    )

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

    def execute(self, context):
        # trace the alpha channel with openCV
        image_data = trace_alpha(self.filepath, self.expansion_pixels, self.alpha_threshold, self.epsilon)
        # sort out the hierarchy of outlines returned by openCV
        outlines = outer_contours(image_data)
        # load the image and create a shader
        image = bpy.data.images.load(self.filepath)
        material = create_material(image)
        for outline in outlines:
            # create the blender objects
            outerPoly = create_blender_polygon(outline, 1.0)
            apply_material(outerPoly, material)
        return {"FINISHED"}
 

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_Alpha)
    bpy.types.TOPBAR_MT_file_import.append(menu_func)

def unregister():
    bpy.utils.unregister_class(Import_Image_With_Alpha)
    bpy.types.TOPBAR_MT_file_import.remove(menu_func)

if __name__ == "__main__":
    register()

I've defined a few properties, like expansion_pixels and alpha_threshold, but I'm unsure why they don't appear with the Adjust Last Operation panel.

Operator called by another operator does not trigger Adjust Last Operation panel

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?

added 91 characters in body; edited tags
Source Link
Harry McKenzie
  • 14.5k
  • 11
  • 34
  • 74

Having trouble Trouble setting up an operator to have adjustable parameterswith Adjust Last Operation panel

I have an operator that I want to have controlled by adjustable parameters when it is invoked. It uses openCV to load an image and then traces the alpha channel of that image to create polygons. I can get it to mostly work, but I don't see my parameters in the 3D viewport lower left widget, whatever that's calledAdjust Last Operation panel. Here's the class definition:

I've defined a few properties, like expansion_pixels and alpha_threshold, but I'm unsure why they don't appear as parameterswith the Adjust Last Operation panel.

Having trouble setting up an operator to have adjustable parameters

I have an operator that I want to have controlled by adjustable parameters when it is invoked. It uses openCV to load an image and then traces the alpha channel of that image to create polygons. I can get it to mostly work, but I don't see my parameters in the 3D viewport lower left widget, whatever that's called. Here's the class definition:

I've defined a few properties, like expansion_pixels and alpha_threshold, I'm unsure why they don't appear as parameters.

Trouble setting up an operator with Adjust Last Operation panel

I have an operator that I want to have controlled by adjustable parameters when it is invoked. It uses openCV to load an image and then traces the alpha channel of that image to create polygons. I can get it to mostly work, but I don't see Adjust Last Operation panel. Here's the class definition:

I've defined a few properties, like expansion_pixels and alpha_threshold, but I'm unsure why they don't appear with the Adjust Last Operation panel.

Source Link
stib
  • 1.1k
  • 1
  • 6
  • 14
Loading