<aside> 🔗 Twitter / Website / Newsletter / Gumroad

</aside>

Table of Contents

Command Line

# Run Blender and enter REPL
$ blender --python-console

# Run a script from command line
$ blender model.blend -P script.py

# Run script in background (without UI)
$ blender model.blend -b -P script.py

# Passing custom command line arguments 
# Anything after -- will be ignored by Blender
$ blender model.blend -b -P script.py -- arg1 arg2

# And you can access them using sys.argv
>>> import sys
>>> sys.argv[6]

# NOTE: You need to replace 'blender' with full path to
# the Blender executable if it is not on PATH

Start Blender in REPL mode

$ path/to/blender --python-console

Run from command line

$ path/to/blender -P script.py

Run from command line without UI

$ path/to/blender -b -P script.py

Run from command line with custom arguments

$ path/to/blender -P script.py -- arg1 arg2

Use a custom exit code on exceptions

$ path/to/blender --python-exit-code <code>

Objects

Get active object

bpy.context.active_object

Set active object

bpy.context.view_layer.objects.active = object_to_set_active