I wan't to make an operator that has button in it that is another operator, that would call some method in original operator.
In the example bellow I want to rename object, after I click on Run. Confusing part is that, although execute_function in MineTestClass is called, nothing happens. And then if I call Execute operator from Search menu, it renames object correctly.
import bpy, bmesh
import mathutils
import os
from mathutils import Vector
bpy.types.Scene.current_operator = None
class MineExecuteOperator(bpy.types.Operator):
bl_idname = "mine.execute_operator"
bl_label = "Execute operator"
def execute(self, context):
print ("Current Operator: " + str(bpy.types.Scene.current_operator))
bpy.types.Scene.current_operator.execute_function(context)
return {'FINISHED'}
class MineTestClass(bpy.types.Operator):
bl_idname = "mine.test_class"
bl_label = "Test Class"
bl_options = {'REGISTER', 'UNDO'}
new_name = bpy.props.StringProperty()
def execute_function(self, context):
obj = bpy.context.selected_objects[0]
obj.name = self.new_name
def invoke(self, context, event):
bpy.types.Scene.current_operator = self
return {"FINISHED"}
def draw(self, context):
layout = self.layout
box = layout.box()
box.prop(self, 'new_name', expand=True, text="Name")
box.operator("mine.execute_operator", text="Run")
def register():
bpy.utils.register_class(MineExecuteOperator)
bpy.utils.register_class(MineTestClass)
def unregister():
bpy.utils.unregister_class(MineExecuteOperator)
bpy.utils.unregister_class(MineTestClass)