Two operators with the same button, it's possible?

In my addon, I have a button that launches me an operator, and I want the same button gives me another operator (modal operator). It is possible to launch two operators with the same button? My modal operator :

def modal(self, context, event):
if event.type == 'RIGHTMOUSE':
...code...
return {'PASS_THROUGH'}

def execute(self, context):
wm = context.window_manager
return {'RUNNING_MODAL'}


Check Text Editor Templates: Operator Simple and Operator Modal

Imagine the modal operator has bl_idname = "object.some_generic_modal". In the execute function of your other (non modal) operator you could make a direct operator call:

def execute(self, context):

# call the other operator
bpy.ops.object.some_generic_modal()

return {'FINISHED'}


However, to avoid the separation and extra boilerplate, you might want to stick your one-off code in the invoke of the modal operator and call that directly instead.

To clarify: with the term one-off code I meant the code which just needs to be executed once, prior to the continuous modal operator.

• Thank you, it works. For cons, I did not understand well understood the second method : stick one-off code in the invoke … Here is my modal operator: def modal(self, context, event): if event.type == 'RIGHTMOUSE': ..... my code ..... return {'PASS_THROUGH'} def execute(self, context): wm = context.window_manager wm.modal_handler_add(self) return {'RUNNING_MODAL'} – Logiquefloue Feb 17 '15 at 9:32
• please edit your own original post and add your code to clarify it. Code fragments aren't formatted nicely in answer-comment section. – zeffii Feb 17 '15 at 9:57
• OK, at this moment you seem to have two operators, (one calls the other). Consider using just one, the modal operator, it can execute code before going into modal mode – zeffii Feb 17 '15 at 10:09
• OK, now I understand better the "Modal Operator." Now I think this is not the right operator I need. I want to start an update operator when you select an object (such as the fact Blender to update the names of objects). So I need to detect the mouse click and call operator MyUpdate (self). You think I have to go through a modal operator? – Logiquefloue Feb 18 '15 at 8:56
• @Logiquefloue with your new understanding I suggest you start a new question specifying in more detail what you want to be able to do (the bigger picture of the addon), if it can be done then people will suggest strategies or example code. But modal operator sounds reasonable, it will stay alive until ended and it is intended to receive events like keyboard and mouse. – zeffii Feb 18 '15 at 10:04