Python call operator from another operator

Hi

Sorry I’m stuck. how can I call an operator from another operator? I did this:

‘’'class VIEWPORT_RENDER_ANIMATION(bpy.types.Operator):
“”“Viewport Render Animation”“”
bl_idname = “viewport.render_animation”
bl_label = “Render Animation”

    def execute(self, context):
    bpy.ops.camera.turnaround_execute() # !!!!! DOES NOT WORK !!!!!!!
    bpy.ops.camera.turnaround_execute(self, context) # !!!!! DOES NOT WORK !!!!!!!

    # Do someting (this works) 

    return{'FINISHED'}'''

‘’'class CAMERA_TURNAROUND(bpy.types.Operator):
“”“Camera turn around an Object”“”
bl_idname = “camera.turnaround_execute”
bl_label = “Turnaround”

   def execute(self, context):

       # Do someting (this works) 

    return{'FINISHED'}'''

Don’t look at the indents I did them right in my script.

Regards

Marc

Telling us the actual error message would be useful. From the snippets it seems that should work fine.

Are you running this from the script editor or as an installed add-on?

Also you can preserve proper indentation by surrounding your code with three grave accents (`) at the beginning and the end when you post it.

Hi
Try this

bpy.ops.camera.turnaround_execute('INVOKE_DEFAULT')

https://docs.blender.org/api/current/bpy.types.Operator.html

Doesn’t work

I’m running it from the Text Editor in Blender.
[if name == ‘main’: register()]

Got a new version that works “a bit” better:

‘’'class VIEWPORT_RENDER_ANIMATION(bpy.types.Operator):
“”“Viewport Render Animation”“”
bl_idname = “viewport.render_animation”
bl_label = “Render Animation”

def execute(self, context):

    # (1) 
    # executes the called class correctly:
    camera_turnaround = bpy.ops.camera.turnaround_execute() 

    # (2) 
    # without this (1) is not working but gives me the error message:
    # AttributeError: 'set' object has no attribute 'execute'
    camera_turnaround.execute()

‘’'class CAMERA_TURNAROUND(bpy.types.Operator):
“”“Camera turn around an Object”“”
bl_idname = “camera.turnaround_execute”
bl_label = “Turnaround”

def execute(self, context):
    
    # Do something

We need more than “# Do something”. My guess is your trying to do something for 3D view from text editor. You run from 3D view and it will prolly work.

The “Do something” works properly that’s not the problem because this part of the script is coded to run in the 3D viewport.

It’s your code in the other operator. Same as your first post and you can see it works fine.

import bpy


class VIEWPORT_RENDER_ANIMATION(bpy.types.Operator):
    bl_idname = "viewport.render_animation"
    bl_label = "Render Animation"

    def execute(self, context):
        bpy.ops.camera.turnaround_execute()

        return{'FINISHED'}


class CAMERA_TURNAROUND(bpy.types.Operator):
    bl_idname = "camera.turnaround_execute"
    bl_label = "Turnaround"

    def execute(self, context):
        print("Calling operator from another operator")
 

        return{'FINISHED'}
    
    
def register():
    bpy.utils.register_class(VIEWPORT_RENDER_ANIMATION)
    bpy.utils.register_class(CAMERA_TURNAROUND)


def unregister():
    bpy.utils.unregister_class(VIEWPORT_RENDER_ANIMATION)
    bpy.utils.unregister_class(CAMERA_TURNAROUND)


if __name__ == "__main__":
    register()

    # test call
    bpy.ops.viewport.render_animation()

If you run from text editor

bpy.ops.view3d.view_axis(type='FRONT')

You will get

RuntimeError: Operator bpy.ops.view3d.view_axis.poll() failed, context is incorrect
Error: Python script failed, check the message in the system console

Without your code, it’s a guessing game.

You were right it’s the code in the other operator. I will check it thanks.