there are two screens in one blender file,each screen use local camera,i need the camera.name for other code, the code "Cam= bpy.context.scene.camera " just get the result of active camera. i need the the result of local camera in running each screens(ps:running in left screen get the result "0R",running in right screen get the result "0F"). how to write the code?"Cam= bpy.context.scene.local_camera"? following is my full code.want to use local camera name of each screen to select gp layer,how to modify these code?

if ('0F' in cam.name):i=1
if ('0R' in cam.name):i=0    
objectToSelect = bpy.data.objects["Annotations"]
bpy.context.view_layer.objects.active = objectToSelect
  • $\begingroup$ i modify my question, so please tell me how to get the local camera of each screens? not the list of all camera names, just one everytime running. thank you. $\endgroup$
    – lee blues
    Sep 8, 2021 at 8:48
  • $\begingroup$ If running in the context of a 3d view, cam = context.space_data.camera $\endgroup$
    – batFINGER
    Sep 8, 2021 at 11:26
  • $\begingroup$ thanks for answer,i have done on basis of accepted answer, is: C = bpy.context for area in C.screen.areas: if area.type == 'VIEW_3D': cam=C.area.spaces.active.camera $\endgroup$
    – lee blues
    Sep 8, 2021 at 13:20
  • $\begingroup$ Should be: cam = area.spaces.active.camera, have a look at the print call @leeblues $\endgroup$
    – brockmann
    Sep 8, 2021 at 15:52

1 Answer 1


Find all areas of type 'VIEW_3D' and use SpaceView3D.camera attribute on the active space:

import bpy

C = bpy.context

# Iterate through all areas
for area in C.screen.areas:
    # Determine whether the area is of type VIEW_3D
    if area.type == 'VIEW_3D':
        # Get the active space (SpaceView3D) print the actual attribute
        print ("Object reference:", area.spaces.active.camera)
        print ("Name:", area.spaces.active.camera.name)

Console Output (object reference and object name per viewport):

Object reference: <bpy_struct, Object("Camera") at 0x7fb1518c7008>
Name: Camera

Object reference: <bpy_struct, Object("Camera2") at 0x7fb1518c7008>
Name: Camera2


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .