I have a scaffolding setup with multiple cameras locked on to a target. I plan to use this to render a model from various positions. This loop has worked for everything else such as changing name and adding constraints but I can not get the logic to work for renders.

The filename changes just fine, running context.view_layer.objects.active will report the camera is changed correctly, as does the UI, however, the render output is simply multiple renders of the same camera...it never changes. Is there a different way to force each camera to actively render other than what I have tried here?

obj_in_scene = bpy.context.scene.collection.all_objects

for cam in obj_in_scene:
    if cam.type == 'CAMERA'
        bpy.context.view_layer.objects.active = cam
        file = os.path.join("/home/jruch/", cam.name)
        bpy.context.scene.render.filepath = file
        bpy.ops.render.render(write_still = True)

I have also tried building a dedicated list object to iterate through, but it would not cycle the camera's active status as well the filtered "all object" context I used about. What am I missing here?

  • $\begingroup$ You're setting the camera object as active object, but not as active camera. $\endgroup$
    – Robert Gützkow
    Nov 23, 2019 at 18:23

1 Answer 1


Assign the camera object to Scene.camera to make it the active cam of the scene:

import bpy

scn = bpy.context.scene

for obj in scn.objects:
    if obj.type == 'CAMERA':
        scn.camera = obj
        scn.render.filepath = obj.name
  • $\begingroup$ Holy flippin' crap!!!! I can't believe it was that easy...Context is indeed everything, thank you so much, this definitely fixed it :) $\endgroup$ Nov 23, 2019 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.