Often used values and operations¶
Here, we list some frequently used parts of the API, for varying types of data.
Access instance attribute
Note that where values are listed as attributes of classes, such as Camera.lens
or Scene.camera
, you need
to access the attribute on an instance of that class, not on the class itself.
Example: to get the active camera access bpy.context.scene.camera
or bpy.data.scenes["myscene"]
(and not Scene.camera
).
Scene¶
- Current scene:
bpy.context.scene
(read-only)
Objects¶
- Type of an object:
Object.type
(read-only) - Active object:
bpy.context.active_object
(read-only) - Selected objects:
bpy.context.selected_objects
(read-only) - Delete selected objects:
bpy.ops.object.delete()
Camera¶
- Active camera object:
Scene.camera
(returns the camera object, not camera object data) - Type:
Camera.type
("PERSP", "ORTHO", ...) - Lens unit:
Camera.lens_unit
(either "MILLIMETERS" or "FOV") - Focal length:
Camera.lens
(in mm) - Field of view (horizontal):
Camera.angle
(in radians) - Clipping distances:
Camera.clip_start
,Camera.clip_end
Rendering¶
- Image resolution:
- Width:
Scene.render.settings.resolution_x
- Height:
Scene.render.settings.resolution_y
- Percentage:
Scene.render.settings.resolution_percentage
- Width:
- Output file:
Scene.render.filepath
- Image output type:
Scene.render.image_settings.file_format
("PNG", "JPEG", ...) - Number of samples per pixel (Cycles):
Scene.cycles.samples
- Render current scene:
bpy.ops.render.render()
. See parameters how to control the specific type of render (still image versus animation) and whether to save output
Animation¶
- Current frame
Scene.frame_current
- Frame range:
Scene.frame_start
,Scene.frame_end
- Frame rate:
Scene.render.fps
File I/O¶
- Save the current session to a specific file:
bpy.ops.wm.save_as_mainfile()
- Open Blend file
bpy.ops.wm.open_mainfile()
- Import a file (call depends on file type):
- Export a file (call depends on file type) follows the same call names. For scene export see here and here, for mesh export see here.
Last update:
07 March 2024 10:58:08
•