My operator duplicates the active object, adds a solidify modifier to it, then applies it.
When run from my panel it works EXCEPT it does not apply the modifier and I can see it still under the duped object in the Outliner (I can then manual apply it, apparently correctly).
When I run the operator directly from the Python Console it DOES apply.
I've verified that after the duplicate, the new object is active and the sole selected object.
I must being doing something wrong that only manifests in a panel context, but I'm stumped. Below is the complete test script.
# Blender 2.82a
import bpy
class TestSolidifyOp(bpy.types.Operator):
bl_idname = "object.test_solidify"
bl_label = "Test solidify"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
orig=context.active_object
bpy.ops.object.duplicate()
ob = context.active_object
if orig is ob: # Just to show orig obj is NOT still active
return{'CANCELLED'}
mod = ob.modifiers.new("Solidify", 'SOLIDIFY')
mod.thickness = -1
bpy.ops.object.modifier_apply(modifier="Solidify")
return {'FINISHED'}
class TestSolidifyPanel(bpy.types.Panel):
bl_label = "Test solidify Panel"
bl_idname = "PANEL_PT_tsolid"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
@classmethod
def poll(cls, context):
return (context.mode == 'OBJECT')
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("object.test_solidify")
if __name__ == "__main__":
bpy.utils.register_class(TestSolidifyOp)
bpy.utils.register_class(TestSolidifyPanel)