I could just use:
obj_camera = bpy.data.objects["Camera"]
to get the camera, but it is possible to have a scene with multiple cameras.
So if that is the case, how can I choose the active one?
The property you are looking for is 'Scene.camera'.
If you have 'python tooltips' enabled in the user preferences you can hover over the camera field in the 'Scene' tab of the 'Properties' area, to reveal the python code for this property:
The code to access this property for the current scene and assign it to a variable is:
obj_camera = bpy.context.scene.camera
"active" is a weak definition, there is the scene camera (can also be None
), but it could also mean the active object and that object being a camera. A special case is operator Set active object as camera, which makes an arbitrary object the scene camera.
cam_ob = bpy.context.scene.camera
if cam_ob is None:
print("no scene camera")
elif cam_ob.type == 'CAMERA':
print("regular scene cam")
else:
print("%s object as camera" % cam_ob.type)
ob = bpy.context.object
if ob is not None and ob.type == 'CAMERA':
print("Active camera object")
I use the following code:
cameras_obj = [cam for cam in bpy.data.objects if cam.type == 'CAMERA']
for cam in cameras_obj:
if cam.hide_render:
print("la camara {} esta desactivada".format(cam.name))
else:
print("la camara {} esta activada".format(cam.name))
bpy.context.scene.objects
instead.
$\endgroup$
Commented
Sep 6, 2021 at 14:06
hide_render
was an object property that ... stopped an object from being rendered, (which doesn't really matter for a non rendered object like a camera, empty etc)
$\endgroup$
Commented
Sep 6, 2021 at 14:19