4
$\begingroup$

How can I batch render multiple blend files consecutively? Are there different ways of doing this? If so, what would be an easy method?

I'm guessing there will be a command prompt method of some kind but I'm not very familiar with this. (although I'd love some pointers)

Basically what I'm looking for is a way to render a given blend file which executes the compositor nodes and saves the images connected to the file output node. When finished, I'd like the blend file to close and in it's turn open the next given blend file and so on and so on...

I'm not looking to render multiple scenes or render layers but actual blend files with it's predefined render settings. Also, I'm aware that there are some render managers available but due to the lack of knowledge I'm not able to figure out how to set these up. (not really looking for a render manager here but an easy method to do batch rendering on the go) I'm sure render managers have their advantages but I'm currently only looking to simplify some basic batch rendering (without having to get up in the middle of the night just to press a single button).

$\endgroup$
9

2 Answers 2

16
$\begingroup$

Basics of Blender's CLI (Command line interface)

The command line is definitely the way to go. Here is a little training that should be enough to get anyone up and running:

blender

Is the command to run Blender from the command line (you may need to setup an alias to have this on Mac or Linux).

blender -b 

-b is a flag that will run Blender in background mode. This is generally what you eventually want when rendering because it is generally faster. However, until you are confident with the command line, you may want to load the UI anyway, so that you can see what it's doing. To do so, simply omit the -b flag. Note that to do the rest of these commands effectively, you must ensure that you have the -b flag enabled.

blender -b filename.blend

Will open the file in the background, but still close immediately. This is not very useful, though, so we do something like this...

blender -b filename.blend -a

This will render out the animation as if you had opened the file and hit "Render Animation."

blender -b filename.blend -f framenumber

This will render out only the frame that was named, e.g.,

blender -b test.blend -f 10

will only render frame 10, then close.


Multi-file rendering

You can, however, string multiple files together. Suppose you are in a folder that has three blend files a.blend, b.blend, and c.blend. You want to render the 15th frame of a.blend, the entire b.blend animation, and the first frame of c.blend.

blender -b a.blend -f 15 b.blend -a c.blend -f 1

This command accomplishes this for us quite easily. Note that this is essentially the same thing as writing the following.

blender -b a.blend -f 15
blender -b b.blend -a
blender -b c.blend -f 1

In most command lines, you can also replace it with the following.

blender -b a.blend -f 15; blender -b b.blend -a; blender -b c.blend -f 1

Note that this is just the previous commands strung together on one line and separated by semicolons.


A bit about directories

There is something when using the command line called the current directory. You can change directory (the current directory) with the cd command. The above assumes that all of the blend files are in the current directory which means that you can leave off the absolute file paths.

Suppose in the command above, we want to access three blend files that are on the desktop. We could cd into the desktop (change the current directory to the desktop), so that the files can be accessed relative to that directory. On Unix systems (mostly Linux and MacOS), you could do something like this.

cd /Users/Username/Desktop/

The user's home directory has a shortcut ~, so this is the same as the following.

cd ~/Desktop/

Default preferences for the terminal probably open it where the current directory is the user's home directory, so you can probably just do...

cd Desktop/

To see what is in the folder you are in, you can use...

ls       # Mac/Linux

dir      # Windows

To see the folder path...

pwd      # Mac/Linux 

cd       # Windows (just use change directory without arguments)

The clunky way - absolute paths

That said, you could just use absolute paths and completely disregard the current directory stuff. I wanted to avoid showing this because of the difference between Unix and Window's ways of writing paths. Unix separates folders with / and Windows separates folders with \. I'll be showing the Unix style in this example. Note the use of the ~...see above for what this means.

blender -b ~/Desktop/a.blend -f 15 ~/Documents/BlendFiles/b.blend -a /Users/Freddy/Desktop/c.blend -f 1

So if the Desktop is in the Freddy directory, a.blend and c.blend are both in the same folder.


Paths with spaces in them

One problem that you may encounter as Delagone mentioned in the comments is something like trying to navigate to:

/Users/Freddy/My Folder/

...where My Folder/ has a space in it. Because the command line separates arguments by spaces, you'll need to put double quotes around that argument to tell the command line to treat it all as one argument. For example, you could do something like the following.

cd "/Users/Freddy/My Folder"

This is one reason why most programmers tend to name folders without spaces; it makes it easier when working from the command line to navigate. Instead you can always name folders with camel-case MyFolder or with underscores my_folder.

If you are on a Unix-based system (I've not yet tested this on Windows), you can also escape the space and leave out the quotes. This is the default behavior for tab auto-completion on a Mac, while the quotes are default for Windows.

cd /Users/Freddy/My\ Folder/

The \ is the escape character and tells the command line to not interpret the next character in the usual way. In this case, it makes it treat it as a regular space character without separating them as arguments.

$\endgroup$
6
  • $\begingroup$ Thanks for the help! i will be testing this later today. I'm not quite sure how the commandline knows exactly where these blendfiles are located on my harddrive. $\endgroup$
    – Delagone
    Commented Mar 2, 2017 at 9:28
  • $\begingroup$ @Delagone This is if the blend files are in the current directory. I'll edit my answer to show some of this... $\endgroup$
    – Jake Dube
    Commented Mar 2, 2017 at 14:15
  • $\begingroup$ Thank you for the great answer! Finally got it working over the weekend. Had some problems with the commandline not recognizing spaces in filename locations. therefore I had to use quotes. C:\Program Files\Blender Foundation\Blender\blender.exe should become "C:\Program Files\Blender Foundation\Blender\blender.exe" when using the commandline (current OS: windows 8.1) to prompt file locations. Note the space in the name Blender Foundation. It's up and running smoothly now. People like you make this site as awesome as it is. Keep up the great work! $\endgroup$
    – Delagone
    Commented Mar 6, 2017 at 8:17
  • $\begingroup$ @Delagone Glad I could help. These are just the basics of the command line that computer scientists just have to know. It's always wonderful to see other users capitalizing on this powerful tool as well. You're right about the quotes as well, I'll include that in my answer... $\endgroup$
    – Jake Dube
    Commented Mar 6, 2017 at 12:29
  • 1
    $\begingroup$ @brockmann This answer explains it clearly for those who are less used to the command line than you and I are. It is a different type of explanation. The manual doesn't need to (and shouldn't) look like this, but sometimes new things need more explanation than a listing of flags... $\endgroup$
    – Jake Dube
    Commented Mar 6, 2017 at 17:31
1
$\begingroup$

If you are linux user my answer would allow you to render all .blend files in a specific directory. Open terminal in the directory and run the following commands:

First I,ll start by creating bash file

touch script.sh

Then give it permission to execute

sudo chmod a+x script.sh

Open the file,you can use your text editor or directly from terminal

nano script.sh Past the following code :

#!/bin/bash
i=1
for f in *.blend; do 
blender -b "$f" -P hi.py -f $i
((i=i+1))
echo $i ;
done    

Run the script using :

./script.sh

You will find your renders in :

/tmp

Named as 0001.png 0002.png and so on.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .