3
$\begingroup$

Let's say I have 4 cameras on a scene:

enter image description here

I would like to render with the first camera, see what it looks like, then switch to the "next" camera quickly and see what that render looks like.

Currently, to switch cameras I have to click on a camera and set it as active and finally I can render (I don't have a number pad so I have to go to the menu and set it each time; else I'd use Ctrl+0). What I would like to know is whether there is a way to switch cameras and set it as active all in one step?

EDIT:
I'm not asking how to set a camera as active, that's doable via menu, what I'm asking for is a guide for a "quick toggle" between cameras; a quick way to switch active cameras without an animation.

$\endgroup$
  • 1
    $\begingroup$ possible duplicate of How can I make a camera the active one? $\endgroup$ – Ray Mairlot Mar 13 '15 at 18:16
  • 1
    $\begingroup$ Well, I wouldn't say that it's a duplicate @RayMairlot as I know how to set a camera as active, but what I'm looking for is a "quick toggle" between cameras. Though the "animation" section from the link above does point me in a simple direction IF I was looking to do an animation. Also, thanks for taking the time and finding that link, if that's the only way I can do it then I'll just create an animation (though I prefer not to). $\endgroup$ – SoluableNonagon Mar 13 '15 at 18:19
  • 2
    $\begingroup$ If you used the 'markers' solution, you would be able to use left and right arrow keys to switch between markers (if markers were 1 frame apart), which would switch the cameras. $\endgroup$ – Ray Mairlot Mar 13 '15 at 18:25
  • $\begingroup$ Alright, I haven't tried that, still a beginner. Thanks. $\endgroup$ – SoluableNonagon Mar 13 '15 at 18:28
2
$\begingroup$

go in scene settings tab
enter image description here
click on the camera name
enter image description here
choose the camera you want as active and click
enter image description here

$\endgroup$
  • $\begingroup$ This is pretty easy. Not bad. I was hoping for shortcut keys, like Alt+Tab, but this is a nice quick way. And thanks for the images. $\endgroup$ – SoluableNonagon Mar 13 '15 at 18:24
  • $\begingroup$ the other method needs more time to set up, but is faster afterwards and gives you a shortcup. $\endgroup$ – Bithur Mar 13 '15 at 18:32
10
$\begingroup$

It's possible with a little addon:

bl_info = {
    "name": "Cycle Cameras",
    "author": "CoDEmanX",
    "version": (1, 0),
    "blender": (2, 65, 0),
    "location": "View3D > Ctrl + Shift + Left/Right Arrow",
    "description": "Switch scene camera to next or previous camera object",
    "warning": "",
    "wiki_url": "",
    "category": "3D View"}

import bpy

class VIEW3D_OT_cycle_cameras(bpy.types.Operator):
    """Cycle through available cameras"""
    bl_idname = "view3d.cycle_cameras"
    bl_label = "Cycle Cameras"
    bl_options = {'REGISTER', 'UNDO'}

    direction = bpy.props.EnumProperty(
        name="Direction",
        items=(
            ('FORWARD', "Forward", "Next camera (alphabetically)"),
            ('BACKWARD', "Backward", "Previous camera (alphabetically)"),
        ),
        default='FORWARD'
    )

    def execute(self, context):
        scene = context.scene
        cam_objects = [ob for ob in bpy.data.objects if ob.type == 'CAMERA']

        if len(cam_objects) == 0:
            return {'CANCELLED'}

        try:
            idx = cam_objects.index(scene.camera)
            new_idx = (idx + 1 if self.direction == 'FORWARD' else idx - 1) % len(cam_objects)
        except ValueError:
            new_idx = 0

        context.scene.camera = cam_objects[new_idx]
        return {'FINISHED'}


addon_keymaps = []

def register():
    bpy.utils.register_module(__name__)

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new(VIEW3D_OT_cycle_cameras.bl_idname, 'RIGHT_ARROW', 'PRESS', ctrl=True, shift=True)
        kmi.properties.direction = 'FORWARD'
        addon_keymaps.append((km, kmi))
        kmi = km.keymap_items.new(VIEW3D_OT_cycle_cameras.bl_idname, 'LEFT_ARROW', 'PRESS', ctrl=True, shift=True)
        kmi.properties.direction = 'BACKWARD'
        addon_keymaps.append((km, kmi))

def unregister():
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()
    bpy.utils.unregister_module(__name__)


if __name__ == "__main__":
    register()

An operator to cycle through available camera objects is bound to CtrlShiftLeft Arrow to go to (alphabetically) previous camera and CtrlShiftRight Arrow to go to next camera.

$\endgroup$
  • 2
    $\begingroup$ CoDEmanX I am very happy to have found this, it should imho be built in... seems like an obvious Missing Feature. $\endgroup$ – Tazling Dec 31 '16 at 21:24
7
$\begingroup$

I have quickly ported it to Blender 2.8x. Thanks for this addon @CoDEmanX. I was about to write my own script but this was much easier and faster.

cycle_cameras.py

bl_info = {
    "name": "Cycle Cameras",
    "author": "CoDEmanX",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "View3D > Ctrl + Shift + Left/Right Arrow",
    "description": "Switch scene camera to next or previous camera object",
    "warning": "",
    "wiki_url": "",
    "category": "3D View"}

import bpy

class VIEW3D_OT_cycle_cameras(bpy.types.Operator):
    """Cycle through available cameras"""
    bl_idname = "view3d.cycle_cameras"
    bl_label = "Cycle Cameras"
    bl_options = {'REGISTER', 'UNDO'}

    direction : bpy.props.EnumProperty(
        name="Direction",
        items=(
            ('FORWARD', "Forward", "Next camera (alphabetically)"),
            ('BACKWARD', "Backward", "Previous camera (alphabetically)"),
        ),
        default='FORWARD'
    )

    def execute(self, context):
        scene = context.scene
        cam_objects = [ob for ob in bpy.data.objects if ob.type == 'CAMERA']

        if len(cam_objects) == 0:
            return {'CANCELLED'}

        try:
            idx = cam_objects.index(scene.camera)
            new_idx = (idx + 1 if self.direction == 'FORWARD' else idx - 1) % len(cam_objects)
        except ValueError:
            new_idx = 0

        context.scene.camera = cam_objects[new_idx]
        return {'FINISHED'}


addon_keymaps = []

def register():
    bpy.utils.register_class(VIEW3D_OT_cycle_cameras)

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon

    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
        kmi = km.keymap_items.new(VIEW3D_OT_cycle_cameras.bl_idname, 'RIGHT_ARROW', 'PRESS', ctrl=True, shift=True)
        kmi.properties.direction = 'FORWARD'
        addon_keymaps.append((km, kmi))
        kmi = km.keymap_items.new(VIEW3D_OT_cycle_cameras.bl_idname, 'LEFT_ARROW', 'PRESS', ctrl=True, shift=True)
        kmi.properties.direction = 'BACKWARD'
        addon_keymaps.append((km, kmi))

def unregister():
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()
    bpy.utils.unregister_class(VIEW3D_OT_cycle_cameras)


if __name__ == "__main__":
    register()
$\endgroup$

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.