To create and add a camera to the scene with the Blender Python API we need to do the following:
1. Create a camera data-block
1 |
camera_data = bpy.data.cameras.new(name='Camera') |
2. Create an object and link it with the camera date-block, we created
1 |
camera_object = bpy.data.objects.new('Camera', camera_data) |
3. Add created camera-object to the scene
1 |
bpy.context.scene.collection.objects.link(camera_object) |
A new camera will be created in the current scene in its main collection.
Final code:
1 2 3 4 5 |
import bpy camera_data = bpy.data.cameras.new(name='Camera') camera_object = bpy.data.objects.new('Camera', camera_data) bpy.context.scene.collection.objects.link(camera_object) |