All classes are basically the same, just one line of code is different
bpy.context.space_data.camera = bpy.data.objects["C_0V0"]
bl_info = {
"name": "CamS",
"description": "",
"author": "Jim lee",
"version": (1, 0, 0),
"blender": (3, 3, 0),
"location": "",
"warning": "",
"wiki_url": "",
"category": "My"
}
import bpy
class C_0V0(bpy.types.Operator):
bl_idname = "cam.c0v0"
bl_label = "C_0V0"
cam_name = "C_0V0"
def execute(self, context):
C = bpy.context
C.object.lock_scale = (True, True, True)
C.object.lock_rotation = (True, True, True)
C.object.lock_location = (True, True, True)
# select cam
C.space_data.camera = bpy.data.objects["C_0V0"]
# Select Active Cam
for area in C.screen.areas:
if area.type == 'VIEW_3D':
A = C.area.spaces.active.camera
C.scene.camera = bpy.data.objects[A.name]
C.space_data.shading.color_type = 'OBJECT'
C.space_data.region_3d.view_perspective = 'CAMERA'
bpy.data.objects[A.name].lock_scale = (True, True, True)
bpy.data.objects[A.name].lock_location = (True, True, True)
bpy.data.objects[A.name].lock_rotation = (True, True, True)
bpy.data.objects[A.name].scale = (1, 1, 1)
bpy.data.cameras[A.name].display_size = 0.05
bpy.data.cameras[A.name].background_images[0].alpha = 0
bpy.data.cameras[A.name].dof.use_dof = False
bpy.data.cameras[A.name].clip_start = 25
bpy.data.cameras[A.name].clip_end = 100000
bpy.data.cameras[A.name].background_images[0].scale = 1
bpy.data.cameras[A.name].background_images[1].scale = 1
bpy.data.cameras[A.name].background_images[2].scale = 1
bpy.ops.view3d.view_center_camera()
bpy.ops.image.reload()
if C.object.mode == 'OBJECT':
bpy.ops.object.select_all(action='DESELECT')
objectToSelect = bpy.data.objects[A.name]
objectToSelect.select_set(True)
C.view_layer.objects.active = objectToSelect
C.view_layer.objects.active = objectToSelect
return {'FINISHED'}
class C_0V1(bpy.types.Operator):
bl_idname = "cam.c0v1"
bl_label = "C_0V1"
cam_name = "C_0V1"
def execute(self, context):
C = bpy.context
C.object.lock_scale = (True, True, True)
C.object.lock_rotation = (True, True, True)
C.object.lock_location = (True, True, True)
# select cam
C.space_data.camera = bpy.data.objects["C_0V1"]
# Select Active Cam
for area in C.screen.areas:
if area.type == 'VIEW_3D':
A = C.area.spaces.active.camera
C.scene.camera = bpy.data.objects[A.name]
C.space_data.shading.color_type = 'OBJECT'
C.space_data.region_3d.view_perspective = 'CAMERA'
# bpy.data.cameras[A.name].photographer.longedge = 4096
bpy.data.objects[A.name].lock_scale = (True, True, True)
bpy.data.objects[A.name].lock_location = (True, True, True)
bpy.data.objects[A.name].lock_rotation = (True, True, True)
bpy.data.objects[A.name].scale = (1, 1, 1)
bpy.data.cameras[A.name].display_size = 0.05
bpy.data.cameras[A.name].background_images[0].alpha = 0
bpy.data.cameras[A.name].dof.use_dof = False
bpy.data.cameras[A.name].clip_start = 25
bpy.data.cameras[A.name].clip_end = 100000
bpy.data.cameras[A.name].background_images[0].scale = 1
bpy.data.cameras[A.name].background_images[1].scale = 1
bpy.data.cameras[A.name].background_images[2].scale = 1
bpy.ops.view3d.view_center_camera()
bpy.ops.image.reload()
if C.object.mode == 'OBJECT':
bpy.ops.object.select_all(action='DESELECT')
objectToSelect = bpy.data.objects[A.name]
objectToSelect.select_set(True)
C.view_layer.objects.active = objectToSelect
C.view_layer.objects.active = objectToSelect
return {'FINISHED'}
addon_keymaps = []
def register():
bpy.utils.register_class(Cam_0V0)
bpy.utils.register_class(Cam_0V1)
def unregister():
bpy.utils.unregister_class(Cam_0V0)
bpy.utils.unregister_class(Cam_0V1)
if __name__ == "__main__":
register()