2.5 Script - Camera Switcher

This is my first script.

This script create a new panel in the property panel with one Button for each camera, to change between cameras.


import bpy
from bpy.props import StringProperty

#TODO
#Delete camera -> Delete operator
#Change scene -> Recreate panel.

class Camera_Switcher_Operator(bpy.types.Operator):
    bl_idname = 'seleccionarCamara'
    bl_label  = 'seleccionarCamara'
    
    cn = StringProperty(name="cn", description="Camera name", default="", maxlen=0)
       
    def execute(self, context):
        props = self.properties
        bpy.ops.object.select_name(name=props.cn)#Select
        bpy.ops.view3d.object_as_camera() #Ctrl+0
        return {'FINISHED'}
    

def _draw(self, context):
    layout = self.layout
    for camera in bpy.context.scene.objects:
        if camera.type == 'CAMERA':
            row = layout.row()
            row.operator(Camera_Switcher_Operator.bl_idname, text=camera.name).cn = camera.name
        


class Camera_Switcher_Panel(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_label = "Camera Switcher"
    bl_default_closed = False
    
    draw = _draw


Saludos.