Access Blender Scene Properties via bpy.context
This guide explains how to access and modify active scene properties
in Blender using the Python API's bpy.context interface.
You will learn the fundamental syntax for referencing the current scene,
how to inspect and change standard settings like render engine and frame
ranges, and how to handle custom scene-level properties directly through
Python scripts.
Accessing the Active Scene Object
In Blender's Python API (bpy), the currently active
scene is accessed directly through bpy.context.scene. This
reference returns a bpy.types.Scene object representing the
scene active in the current workspace.
import bpy
# Reference the active scene
scene = bpy.context.scene
# Print the name of the active scene
print(scene.name)Reading and Modifying Built-in Properties
Once you have a reference to bpy.context.scene, you can
read and write standard scene settings.
Timeline and Frame Settings
You can query or update the current frame, start frame, and end frame of the animation timeline:
import bpy
scene = bpy.context.scene
# Set timeline boundaries
scene.frame_start = 1
scene.frame_end = 250
# Set the current playhead position
scene.frame_current = 50
# Access frame rate settings
scene.render.fps = 24
scene.render.fps_base = 1.0Render Engine and Output Settings
Render configurations such as the active render engine, resolution,
and output file formats reside under scene.render:
import bpy
scene = bpy.context.scene
# Switch render engine ('CYCLES', 'BLENDER_EEVEE_NEXT', 'BLENDER_WORKBENCH')
scene.render.engine = 'CYCLES'
# Set render resolution
scene.render.resolution_x = 1920
scene.render.resolution_y = 1080
scene.render.resolution_percentage = 100
# Set output file format
scene.render.image_settings.file_format = 'PNG'Active Camera and World Settings
Scene-level object references and environmental data can also be assigned or checked directly:
import bpy
scene = bpy.context.scene
# Set the active camera
scene.camera = bpy.data.objects.get("Camera")
# Access the active world environment
if scene.world:
print("World name:", scene.world.name)Working with Custom Scene Properties
ID Properties (Dictionary-style)
You can assign arbitrary data to a scene dynamically using dictionary-style key assignment:
import bpy
scene = bpy.context.scene
# Create or update a custom property
scene["project_version"] = "1.0.4"
# Read the custom property
version = scene.get("project_version", "default_val")
print(version)Registered Type Properties (bpy.props)
For scripts and add-ons requiring strict data types and UI
integration, register properties to bpy.types.Scene:
import bpy
# Define and register a custom property
bpy.types.Scene.my_custom_float = bpy.props.FloatProperty(
name="Custom Float",
default=1.0
)
# Access and modify the registered property via context
bpy.context.scene.my_custom_float = 3.5
print(bpy.context.scene.my_custom_float)Context Considerations
bpy.context.scene is the preferred way to target the
scene currently in use by the operator or UI. If you are writing scripts
that execute without an active window or UI context (such as certain
background tasks or batch processing), you can alternatively reference
scenes explicitly by name using
bpy.data.scenes["SceneName"].