3 Steps to Call Blender from the CLI — Have It Do Anything!

Yunus Emre Adas
Developers’ Corner
5 min readOct 12, 2024

If you think Blender is already a powerhouse for 3D modeling, animation, and rendering, imagine being able to tap into this power directly from the command line.

If you like automating tasks, processing batches of files, or if you just want to script your 3D creations in a geeky sort of way, well, you’ll be glad to know that Blender boasts some impressively powerful command-line interface capabilities.

Below, I’ll demonstrate how to run Blender from within the command line, execute scripts written in Python, and handle Blender like a boss. I’ll also use a couple of practical examples, such as exporting models and cleaning lights from a scene.

So let’s start!

If you are not a member, you can access to full text here.

Accessing Blender from the Command Line

Blender’s command-line access can be a bit daunting at first; you might actually find yourself puzzled why you had ever opened the UI after getting used to it.

You can run Blender from the CLI by using the following basic syntax:

blender [arguments.]

For this to work, you should have added Blender to your system’s PATH or change to the directory containing the Blender executable in your terminal. An example of what that would look like for a Windows machine might be something such as:

“C:\\Program Files\\Blender Foundation\\Blender 4.2\\blender.exe” [arguments.]

Running Blender in Headless Mode

Blender’s GUI is nice, but often enough if you’re running scripts or automating tasks, you don’t need it. Fortunately Blender has a “headless” mode, in which it runs without opening the

Running Blender in Headless Mode

This is very useful for render or processing jobs where you don’t need to see anything on screen.

Finally, let’s have some fun with Blender using two important CLI arguments: ` — python-expression` and `-P`.

Using ` — python-expression`: Evaluate Python Expression on the Fly

The ` — python-expression` argument in a command provides a way to inject some Python code directly from the command line into Blender. That can be useful if you want to execute simple operations or one-liners without going through the hassle of creating a whole Python script file.

Here is a small example of how printing something in the Blender console can look like from the command line.

Boom! You’ve just executed your first command in Blender through the CLI. Now, let’s take it up a notch.

Adding a Cube
We’re now going to create a new scene and add a cube to it using the — python-expression

Pretty straightforward, isn’t it? The command opens Blender in the background and runs a Python expression that imports Blender’s Python API (`bpy`) and adds a cube to the default scene.

Running Python Scripts

While the ` — python-expression` is cool for quick one-liners, when you need more complex operations, it’s time to use `-P` to run entire Python scripts.

Let’s say you have a Python script, `myscript.py`, that performs some operations in Blender.

Running Python Scripts

File Exporting FBX and OBJ

Let’s consider an example of exporting objects in two different formats, namely FBX and OBJ. This will be very helpful if you have a set of Blender files that you want to convert for game engines or other 3D software.

Below is a Python script that exports the active object in the scene as both FBX and OBJ formats:

File Exporting FBX and OBJ

Save this script as `export_objects.py`, and run it from the command line:

This script will export the active object in the scene into both FBX and OBJ format. Files can also be batch processed this way by running similar scripts on multiple `.blend` files, or you can further automate this by looping through objects in the scene.

Delete All Lights in the Scene and Save

Let’s get a little naughty now, delete every light in an open Blender scene. We will then save the file afterwards.

Delete All Lights in the Scene and Save

Bonus Example: Batch Rendering Multiple Files

Want to render many a `.blend` file in the background? Easy peasy! You can batch render a folder of Blender files like so.

Batch Rendering Multiple Files

This snippet loops through each `.blend` file in a directory and renders the first frame out to the specified output location. It doesn’t get much more satisfying than this with automation!

Conclusion

This opens the door to automating tasks, performing batch processing, and scripting complex 3D workflows from the command line. Running Python expressions, full Python scripts, and even batch exporting and rendering-this is the command-line interface to be sure that your hands are on Blender without opening the user interface.

Wrap your workflow around automated tasks, ranging from adding cubes to exporting models by batch, like a pro-save loads of time and have fun with Blender’s Python API.

Feel free to fire up your terminal and start bossing Blender around via the command line. You’ll be mastering 3D creation in no time-in a whole new way.

Have a wonderful day!

Stay connected, stay online.

Thanks for coming this far 🎉

  • 👏 Could you please clap the story to help spread the article? (50 applause).
  • 📧 Also you can subscribe my free newsletter.

You can reach me from the links below:

To access my other articles:

Sign up to discover human stories that deepen your understanding of the world.

Developers’ Corner
Developers’ Corner

Published in Developers’ Corner

A virtual hub for tech enthusiasts eager to enhance their skills in web development, software design, AI, and entrepreneurship. Our publication provides a platform packed with coding tutorials, technical articles, inspiring success stories, and latest advancements in the industry

Yunus Emre Adas
Yunus Emre Adas

Written by Yunus Emre Adas

Web Developer, Part-Time blogger, Solopreneur, Tech Lover. Join my journey and find out who we really are.

Responses (1)

What are your thoughts?

Pretty nice, helped me a lot. I never used python and blender together but I want to. To tell the truth I have some trouble figuring it out, but this article pushed me in a productive direction.
Thanks for your work!