How to edit an instance of an operator that is running.

I was trying to remove the “self._handle” for an operator from another operator. But actually I was wanting the operator executed only once.
The ideal it would be to change an instance (eg .: self.instance) of an operator who is running when I execute this operator again.

I hope I was clear. Here’s an attempt that actually gives a bug. But explains what I’m trying.

import bpy


class ModalOperator(bpy.types.Operator):
    """Move an object with the mouse, example"""
    bl_idname = "object.modal_operator"
    bl_label = "Simple Modal Operator"


    def modal(self, context, event):
        if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
            print(len(self.list))


        elif event.type in {'RIGHTMOUSE', 'ESC'}:
            return {'CANCELLED'}


        return {'PASS_THROUGH'}
    
    def execute(self, context):
        self.list = []


        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}


    def invoke(self, context, event): 
        self.list.append(1)
        #return {'RUNNING_MODAL'}


class Simple_Panel(bpy.types.Panel):
    bl_space_type = "TEXT_EDITOR"
    bl_region_type = "UI"
    bl_label = "Modal_is_running?"


    def draw(self, context):
        layout = self.layout
        layout.operator("object.modal_operator")


def register():
    bpy.utils.register_class(ModalOperator)
    bpy.utils.register_class(Simple_Panel)


if __name__ == "__main__":
    register()


    # test call
    bpy.ops.object.modal_operator() #first execute, then invoke

The answer to that question would help me a lot.

Why do you need this?

I work around the problem. I added to a “bpy.types …” a list with all the objects that will be read on a handle or modal function. Just add an object to list that the function changes.
However, it would be better to simply add the object class that is running.

I’m working on this script, it is a kind of IDE.


There’s a lot still to do.