How to use a single function "invoke" in multiple operators?

There are some ways to perform the same function invoke in different operators. But what is the most recommended? Taking into account: memory, possibility of adding specific instances of operator, convenience…

For example:
Like this?:


import bpy


def invoke(self, context, event):
    print(self.name)
    print(context.region.type)
    self.a = 'a'
    self.b = 'b'
    self.c = 'c'


class FirstOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.first_operator"
    bl_label = "First Object Operator"


    def execute(self, context):
        print(self.specific, self.a, self.b, self.c)
        return {'FINISHED'}
    
    def invoke(self, context, event):
        invoke(self, context, event)
        self.specific = 'operador 1:'
        return self.execute(context)


class SecondOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.second_operator"
    bl_label = "Second Object Operator"


    def execute(self, context):
        print(self.specific, self.c, self.b, self.a)
        return {'FINISHED'}
    
    def invoke(self, context, event):
        invoke(self, context, event)
        self.specific = 'operador 2:'
        return self.execute(context)


bpy.utils.register_class(FirstOperator)
bpy.utils.register_class(SecondOperator)


# test call
bpy.ops.object.first_operator('INVOKE_DEFAULT')
bpy.ops.object.second_operator('INVOKE_DEFAULT')

Or this way?:


import bpy


class InvokeClass():
    def invoke(self, context, event):
        print(self.name)
        print(context.region.type)
        self.a = 'a'
        self.b = 'b'
        self.c = 'c'


class FirstOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.first_operator"
    bl_label = "First Object Operator"


    def execute(self, context):
        print(self.specific, self.a, self.b, self.c)
        return {'FINISHED'}
    
    def invoke(self, context, event):
        InvokeClass.invoke(self, context, event)
        self.specific = 'operador 1:'
        return self.execute(context)


class SecondOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.second_operator"
    bl_label = "Second Object Operator"


    def execute(self, context):
        print(self.specific, self.c, self.b, self.a)
        return {'FINISHED'}
    
    def invoke(self, context, event):
        InvokeClass.invoke(self, context, event)
        self.specific = 'operador 2:'
        return self.execute(context)


bpy.utils.register_class(FirstOperator)
bpy.utils.register_class(SecondOperator)


# test call
bpy.ops.object.first_operator('INVOKE_DEFAULT')
bpy.ops.object.second_operator('INVOKE_DEFAULT')

Or other I don’t know?

Read this.
http://www.swineworld.org/2014/07/inheritance-and-mixin-classes-vs.html

Hi mano-wii,

you can make this:


class InvokeOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.first_operator"
    bl_label = "First Object Operator"

     
    global a = 'a'        
    global b = 'b'
    global c = 'c'

    @classmethod   or    @staticmethod
    def execute(self, context):
       A=functionONE()
       B= functionTWO()
       C= functionTHREE()

       return {'FINISHED'}
    
    def invoke(self, context, event):
        self.specific = 'operador 1:'
        return { ‘RUNNING_MODAL’}

Seen here:

no?

I liked the post from @Linusy about the Michel solution. I can make a Invoke class with the superclass “bpy.types.Operator” and all other classes can be defined in the body of class Invoke.