This guide will walk you through the essentials of using the Blender CLI, from basic syntax to common commands for rendering, Python scripting, and more. We'll leverage insights directly from Blender's built-in help and official manual (Blender 4.4) to get you up and running.
Why Use the Blender CLI?
You might wonder why you'd trade Blender's visual interface for a text-based one. Here are some key advantages:
- Automation: Repetitive tasks can be scripted and executed without manual intervention.
- Batch Processing: Render multiple files, frames, or scenes with a single command.
- Headless Operations: Run Blender on servers or machines without a graphical display (e.g., for render farms).
- Resource Efficiency: CLI operations often consume fewer system resources than running the full GUI.
- Integration: Easily integrate Blender into larger production pipelines and custom toolsets.
- Precision: Directly control parameters that might be less accessible or more cumbersome via the GUI.
Getting Started: Launching the CLI
Accessing Blender's CLI is straightforward. You'll need to open your system's terminal or command prompt:
- Windows: Open Command Prompt (type
cmd
in the Start menu) or PowerShell. Navigate to Blender's installation directory (e.g.,cd "C:\Program Files\Blender Foundation\Blender 4.4"
). Then runblender.exe
. - macOS: Open Terminal (Applications > Utilities). Navigate to the Blender application bundle:
cd /Applications/Blender.app/Contents/MacOS
. Then run./Blender
. - Linux: Open your terminal. If Blender is in your system's PATH (common with package manager installs), you can just type
blender
. Otherwise, navigate to Blender's installation directory and run./blender
.
For detailed, platform-specific instructions, always refer to the official Blender Manual section on Launching from the Command Line.
Once launched with CLI arguments, Blender might not open its GUI, especially if you use commands like -b
for background mode.
Basic Concepts
Before diving into specific commands, let's cover some fundamental principles:
Command Structure
The general syntax for Blender CLI commands is:
blender [args ...] [file] [args ...]
blender
: The command to run the Blender executable.[args ...]
: Global arguments that affect Blender's overall behavior.[file]
: (Optional) The path to a.blend
file you want to operate on.[args ...]
: Arguments that might be specific to the file or operation that follows.
Argument Order is Crucial!
This is a critical point often highlighted by Blender itself. Arguments are executed in the order they are given. A misplaced argument can lead to unexpected behavior or errors.
For example:
blender --background test.blend --render-frame 1 --render-output "/tmp"
This will not render to /tmp
because --render-frame 1
executes before the output path is set.
blender --background --render-output /tmp test.blend --render-frame 1
This also will not render to /tmp
because loading test.blend
overwrites the render output that was set before it.
The correct order in this case would be:
blender --background test.blend --render-output /tmp --render-frame 1
This works as expected because the blend file is loaded first, then the output path is set, and finally, the frame is rendered.
File Paths
When specifying file paths for render outputs or Python scripts:
- Absolute Paths: Provide the full path (e.g.,
/home/user/renders/
orC:\Users\user\renders\
). - Relative Paths: Use
//
at the start of a path to indicate it's relative to the location of the currently open.blend
file. For example, if your blend file is/path/to/project.blend
, then//render_output/
refers to/path/to/render_output/
.
Core CLI Commands
Let's explore the most commonly used commands, categorized by their function.
1. Rendering
This is perhaps the most frequent use of the Blender CLI.
-
-b
or--background
Run Blender in background (headless) mode. Essential for rendering without the GUI. Audio is usually disabled in this mode.Example:
blender -b my_scene.blend -a
-
-a
or--render-anim
Render all frames from the start to the end frame defined in the.blend
file (or overridden by-s
and-e
).Example:
blender -b my_scene.blend -o //renders/anim_frame_#### -F PNG -a
-
-S <name>
or--scene <name>
Set the active scene for rendering.Example:
blender -b my_project.blend -S "Shot_02" -a
-
-f <frame>
or--render-frame <frame>
Render a specific frame or a set of frames.- For a single frame:
-f 10
(renders frame 10) - Relative frames:
-f +5
(renders 5 frames after the scene's start frame),-f -5
(renders 5 frames before the scene's end frame). - Comma-separated list:
-f 1,5,10
(renders frames 1, 5, and 10) - Range:
-f 1..5
(renders frames 1, 2, 3, 4, and 5)
Example:
blender -b my_scene.blend -f 42
- For a single frame:
-
-s <frame>
or--frame-start <frame>
Set the start frame for rendering.Example:
blender -b my_scene.blend -s 10 -e 50 -a
-
-e <frame>
or--frame-end <frame>
Set the end frame for rendering.Example:
blender -b my_scene.blend -s 10 -e 50 -a
-
-j <frames>
or--frame-jump <frames>
Set the frame step. For example,-j 2
renders every second frame.Example:
blender -b my_scene.blend -j 3 -a
-
-o <path>
or--render-output <path>
Set the render output path and filename.- Use
//
for paths relative to the.blend
file. #
characters are replaced by the frame number, with padding.output_##.png
becomesoutput_01.png
,output_02.png
, etc.output_######.png
becomesoutput_000001.png
.
- If no
#
is present, Blender appends####
to the filename.
Example:
blender -b my_scene.blend -o //renders/frame_### -F PNG -a
- Use
-
-E <engine>
or--engine <engine>
Specify the render engine (e.g.,CYCLES
,EEVEE
,WORKBENCH
). Use-E help
to list available engines.Example:
blender -b my_scene.blend -E CYCLES -f 1
-
-t <threads>
or--threads <threads>
Set the number of CPU threads to use (0 for all available system processors).Example:
blender -b my_scene.blend -t 4 -a
Specific Rendering Example: Render frames 10 to 20 of animation_project.blend
using the Cycles engine on an NVIDIA OptiX GPU, outputting as EXR files to a relative folder named hires_frames
:
blender -b animation_project.blend \
-S "MainScene" \
-E CYCLES \
-o //hires_frames/shot1_#### \
-F OPEN_EXR \
-s 10 \
-e 20 \
-a \
-- --cycles-device OPTIX
Cycles Render Options:
These options must follow a double dash (--
).
-
--cycles-device <device>
Set the Cycles render device. Options includeCPU
,CUDA
,OPTIX
,HIP
,ONEAPI
,METAL
. You can also append+CPU
to a GPU device (e.g.,CUDA+CPU
).Example:
blender -b my_scene.blend -E CYCLES -f 1 -- --cycles-device OPTIX
-
--cycles-print-stats
Log statistics about render memory and time usage.
Format Options:
-
-F <format>
or--render-format <format>
Set the output image or video format. Common options:PNG
,JPEG
,OPEN_EXR
,FFMPEG
.Example:
blender -b my_scene.blend -o //my_render -F OPEN_EXR -f 1
-
-x <bool>
or--use-extension <bool>
Set to1
to add the file extension to the output filename,0
to disable. By default, Blender doesn't add the extension automatically when rendering through CLI.When set to
1
, Blender will append the appropriate extension based on your chosen output format (e.g.,.png
,.jpg
,.exr
). This makes files immediately recognizable and usable by other applications without renaming.When set to
0
, Blender omits the extension, which can be useful for custom post-processing scripts that need to handle files in specific ways.Example with extension enabled:
blender -b my_scene.blend -o //my_render -F PNG -x 1 -f 1
Output:my_render0001.png
Example with extension disabled:
blender -b my_scene.blend -o //my_render -F PNG -x 0 -f 1
Output:my_render0001
2. Python Scripting
The CLI is incredibly useful for running Python scripts to modify scenes, automate tasks, or perform custom exports.
-
-P <filepath>
or--python <filepath>
Run the specified Python script file.Example:
blender -b my_scene.blend -P my_script.py
-
--python-text <name>
Run a Python script from a text block within the.blend
file.Example:
blender -b my_scene.blend --python-text "MyInternalScript"
-
--python-expr <expression>
Execute a single Python expression.Example:
blender --python-expr "import bpy; bpy.data.objects['Cube'].location.x = 5.0"
-
--python-console
Run Blender with an interactive Python console. -
-y
or--enable-autoexec
/-Y
or--disable-autoexec
Enable or disable automatic execution of Python scripts within.blend
files (drivers, startup scripts). Disabled by default for security. -
--addons <addon(s)>
Enable a comma-separated list of add-ons.Example:
blender --addons "node_wrangler,my_custom_addon"
Specific Python Scripting Example:
Let's say you have a script move_and_render.py
:
# move_and_render.py
import bpy
import sys
# Get custom argument (e.g., new x_location)
args = sys.argv[sys.argv.index("--") + 1:]
new_x_location = float(args[0]) if args else 0.0
# Ensure 'Cube' exists
if "Cube" in bpy.data.objects:
bpy.data.objects["Cube"].location.x = new_x_location
print(f"Moved Cube to X: {new_x_location}")
else:
print("Error: Cube not found in scene.")
sys.exit(1) # Exit with an error code
# Set render output
bpy.context.scene.render.filepath = "//script_render_output/frame_##"
bpy.context.scene.render.image_settings.file_format = 'PNG'
# Render a single frame
bpy.ops.render.render(write_still=True, animation=False, scene=bpy.context.scene.name)
print(f"Rendered frame {bpy.context.scene.frame_current} to {bpy.context.scene.render.filepath}")
You would run this with:
blender -b my_scene.blend --python-use-system-env -P move_and_render.py -- 10.0
This command runs Blender in the background, loads my_scene.blend
, allows Python to use system environment variables, executes move_and_render.py
, and passes 10.0
as a custom argument to the script. The script then moves the "Cube" object to X=10.0 and renders the current frame to //script_render_output/
.
Passing Arguments to Python Scripts:
To pass custom arguments to your Python script, place them after the --
separator. These arguments will then be accessible in your script via sys.argv
.
Example: blender -b -P my_script.py -- --my-arg value --another-option
Inside my_script.py
:
import sys
args = sys.argv[sys.argv.index("--") + 1:] # Get arguments after --
print(f"My custom arguments: {args}")
# args would be ['--my-arg', 'value', '--another-option']
3. Animation Playback
Blender can act as a command-line animation player. This is particularly useful for quickly reviewing rendered sequences without needing to load them into video editing software or when you need to check animations in their native resolution and frame rate.
-
-a <options> <file(s)>
(when not used with-b
) Launches Blender's animation player to view image sequences or videos directly. The player provides a simple interface to review, scrub through, and evaluate your animations. It supports various image formats and can handle frame sequences with standard naming conventions.Example:
blender -a //renders/frame_####.png
This opens a window displaying the image sequence, allowing you to play, pause, and navigate through the frames. The player automatically detects the frame range based on the available files matching the pattern.
Key sub-options:
-
-p <sx> <sy>
: Playback window position on screen. Coordinates are in pixels from the top-left corner of your primary display.Example:
blender -a -p 100 200 //renders/frame_####.png
(positions the player window 100 pixels from left, 200 from top) -
-f <fps> <fps_base>
: Specify playback frame rate as a fraction. Default is 24 FPS (24/1).Example:
blender -a -f 30 1 //renders/frame_####.png
(plays at 30 FPS)Example:
blender -a -f 24 1.001 //renders/frame_####.png
(plays at 23.976 FPS, common for video) -
-s <frame>
/-e <frame>
: Start/End frame for playback, useful for previewing specific portions of longer animations.Example:
blender -a -s 100 -e 200 //renders/complete_sequence_####.png
(only plays frames 100-200) -
Multiple sequences can be played back in succession by listing them:
Example:
blender -a //shot1_####.png //shot2_####.png //shot3_####.png
-
4. Window and Startup Options
These control how Blender (potentially the GUI) starts up.
-
--factory-startup
Skip reading the user'sstartup.blend
anduserpref.blend
. Useful for ensuring a clean environment for scripts or troubleshooting.Example:
blender --factory-startup -b my_scene.blend -P my_script.py
-
--open-last
Open the most recently opened blend file. -
-w
or--window-border
: Force window with borders. -
-W
or--window-fullscreen
: Force full-screen mode. -
-p <sx> <sy> <w> <h>
or--window-geometry <sx> <sy> <w> <h>
: Set window position and size. -
-M
or--window-maximized
: Force opening maximized. -
-con
or--start-console
(Windows only): Start with the console window open.
5. Logging and Debugging
Useful for diagnosing issues.
-
-d
or--debug
Enable general debugging mode. This enables memory error detection, disables mouse grab (useful for debuggers), and keeps Python'ssys.stdin
. -
--log <match>
Enable specific logging categories. Supports wildcards (*
,^
).Example:
blender --log "wm.operator.*"
to log window manager operator messages.Example:
blender --log "*undo*"
to log all messages related to undo. -
--log-level <level>
Set logging verbosity (higher for more details, -1 for all). -
--log-file <filepath>
Output logs to a specified file.
The manual lists many specific debug flags like --debug-cycles
or --debug-python
.
6. Miscellaneous
-
-v
or--version
Print Blender version and exit. -
-h
or--help
Print the command-line help text and exit. -
-r
or--register
(Windows & Linux) Register.blend
file extension for the current user. -
--app-template <template>
Set the application template to use.Example:
blender --app-template "Video Editing"
-
-noaudio
/-setaudio <device>
Control the audio system.
Basic Error Handling and Troubleshooting
Working with the CLI will inevitably involve some troubleshooting. Here's how to approach common issues:
-
Read the Error Message: Blender often provides informative error messages in the console. This is your first clue.
Cannot open file: ...
: Check if the.blend
file path is correct and if the file exists.Error: ... is not a .blend file
: Ensure you're pointing to a valid Blender file.Python script fail, look in the console for now...
: This indicates an error within your Python script. Blender will print a traceback in the console.- Unknown arguments:
blender -ba test.blend
will exit because-ba
is not a recognized combined argument. Arguments must be separated by spaces.
-
Check Argument Order: As emphasized earlier, the order of arguments matters. If a render isn't saving to the specified output or using the correct settings, review the command for proper ordering.
-
Verify Paths: Double-check all file and directory paths. Typos are common. Ensure relative paths (
//
) are correctly referencing files based on the.blend
file's location. -
Python Script Errors (Tracebacks):
- When a Python script fails, Blender prints a traceback. This shows the sequence of calls that led to the error and the error type (e.g.,
NameError
,TypeError
,FileNotFoundError
). - Look at the last few lines of the traceback to pinpoint the problematic line in your script and the nature of the error.
- Use
print()
statements in your script to debug values and flow, and run Blender with the console visible or log output to a file. - The
--python-exit-code <code>
argument can be useful to make Blender exit with a specific code if a Python script fails, which helps in automated pipelines.
- When a Python script fails, Blender prints a traceback. This shows the sequence of calls that led to the error and the error type (e.g.,
-
Use Debug Flags:
- Start with a general
-d
or--debug
. - If you suspect a specific area (e.g., Cycles, FFmpeg), use more targeted debug flags like
--debug-cycles
or--debug-ffmpeg
. The output can be verbose but highly informative.
- Start with a general
-
Logging:
--log "*"
and--log-level -1
will provide maximum logging information.- Use
--log-file <filepath>
to save extensive logs for later analysis, especially for background processes.
-
Factory Startup for Scripts: If a script behaves unexpectedly, try running it with
--factory-startup
to rule out interference from user preferences or other add-ons.blender --factory-startup -b scene.blend -P script.py
-
Permissions: Ensure Blender has the necessary read/write permissions for the directories it's trying to access (e.g., render output directories, script locations).
-
Check the Console Window: On Windows, use
-con
or launchblender_debug_log.cmd
from Blender's installation directory to ensure the console window stays open and displays messages. On macOS and Linux, messages appear directly in the terminal you launched Blender from.
By systematically checking these points, you can resolve most common CLI issues.
Environment Variables
Blender's behavior can also be influenced by environment variables. These are particularly useful for configuring paths without modifying command-line arguments every time. Some key ones include:
$BLENDER_USER_SCRIPTS
: Directory for user scripts (add-ons, modules).$BLENDER_USER_DATAFILES
: Directory for user data files (icons, translations).$BLENDER_SYSTEM_SCRIPTS
: Directory for additional system-wide scripts.$TMPDIR
(Unix-like) /$TEMP
(Windows): Directory for temporary files.$OCIO
: Path to override the OpenColorIO configuration file.
You can find a more comprehensive list in the blender -h
output or the Blender's Directory Layout section of the manual.
Tips for Success with Blender CLI
- Start Simple: Begin with basic rendering commands before moving to complex scripts.
- Quoting Paths: If your file paths or arguments contain spaces, enclose them in quotes (e.g.,
blender -b "my scene with spaces.blend"
). - Use
--factory-startup
: When testing scripts or renders, use this to ensure your user preferences don't interfere with the expected outcome. - Test Scripts in Blender First: Develop and test your Python scripts within Blender's GUI (Text Editor, Python Console) before running them via CLI.
- Check the Manual: The Blender Manual is your best friend for detailed information on all arguments and sub-commands.
- Redirect Output: For long operations or debugging, redirect standard output and standard error to files:
blender -b scene.blend -a > render_log.txt 2> error_log.txt
(Syntax may vary slightly between shells).
Conclusion
The Blender Command Line Interface is a gateway to enhanced productivity and control. Whether you're automating renders, managing complex scenes with Python, or integrating Blender into a larger pipeline, mastering the CLI will significantly expand what you can achieve with this versatile 3D suite.
Start experimenting with the commands outlined here, consult the blender -h
output for the full list, and don't hesitate to explore the official Blender Manual. The power to automate is now at your fingertips!