Sub topic 14
Selecting an Engine from Python and the Command Line
This chapter assumes you can navigate Blender’s Properties editor, assign a Principled BSDF material, add lights and a camera, and render a still with F12. You will use those skills to automate an engine choice instead of changing it manually.
Selecting the Engine with Python
Blender exposes the active render engine through scene.render.engine. Cycles uses the stable identifier CYCLES. EEVEE’s identifier has changed between Blender versions, so scripts should inspect the available identifiers instead of assuming one fixed string.
import bpy
scene = bpy.context.scene
engine_ids = [
item.identifier
for item in scene.render.bl_rna.properties["engine"].enum_items
]
print("Available engines:", engine_ids)
eevee_id = next(
(engine_id for engine_id in engine_ids
if engine_id.startswith("BLENDER_EEVEE")),
None,
)
if eevee_id is None:
raise RuntimeError("This Blender build does not provide EEVEE")
scene.render.engine = eevee_id
print("Selected engine:", scene.render.engine)The script gets the current scene, lists the engine identifiers supported by the running Blender version, and selects the first identifier beginning with BLENDER_EEVEE. This makes the script more portable across Blender releases.
To select Cycles and configure its main quality settings, use its fixed identifier:
import bpy
scene = bpy.context.scene
scene.render.engine = "CYCLES"
scene.cycles.device = "GPU"
scene.cycles.samples = 128
scene.cycles.use_denoising = True
print("Selected engine:", scene.render.engine)GPU requests GPU rendering, but it works only when a supported device is enabled in Blender’s Preferences. Otherwise, configure scene.cycles.device = "CPU".
Running a Script from the Command Line
Run a Python file with Blender’s --python option. The following example applies the Cycles settings from a file named select_cycles.py:
blender -b scene.blend --python select_cycles.pyThe -b option starts Blender in background mode, without opening the user interface. Use this for repeatable jobs on a render machine or in a build script.
You can also choose the engine directly during a render:
blender -b scene.blend -E CYCLES -o //render_#### -f 1This command does the following:
- Opens
scene.blendin background mode. - Selects Cycles with
-E CYCLES. - Writes the result beside the blend file using the
render_####frame-number pattern. - Renders frame 1 with
-f 1.
The output path and engine appear before the frame argument. A path beginning with // is relative to the directory containing the blend file.
Choosing Between Python and `-E`
Use -E when the engine choice is the only setting that changes. Use Python when the render also needs samples, denoising, device selection, resolution, output format, or version-aware EEVEE detection.
| Method | Best use | Main limitation |
|---|---|---|
| `-E` | A quick, repeatable engine override | Does not configure all quality settings |
| Python | Full, version-aware render configuration | Requires a script and valid Blender API code |
Exercise
Why is detecting the EEVEE identifier in Python safer than always assigning a single hard-coded EEVEE string?
Show answer
Blender has changed EEVEE’s identifier between versions. Inspecting the available identifiers lets the script select the identifier supported by the running Blender.