# How do I render only part of an image via the command line?

I know that it is possible to render from the command line:

https://docs.blender.org/manual/en/dev/render/workflows/command_line.html

I'm tring to make it possible to render a single image on multiple PCs via the sun grid engine. So I want to split the renders up into tiles, so that every pc can render one tile.

The sun grid engine only works via the command line. Is it possible to specify ony a part of the image that should be rendered by the command line? Can I somehow set the render border before rendering?

Maybe someone has another idea of how to do this?

This can be done via a script (external or internal of the .blend file).

I shall name by script textblock script.

import bpy
import sys
argv = sys.argv
argv = argv[argv.index("--") + 1:]

scn = bpy.data.scenes["Scene"]

# get the frame arg
frame = int(argv[4])

# go to the desired frame
scn.frame_set(frame)

# set a unique output path
scn.render.filepath = "//dir/" + str(frame).zfill(4)
for i in range(0, 4):
scn.render.filepath += "_" + argv[i]

# setup the render border
scn.render.use_border = True
scn.render.border_min_x = float(argv[0])
scn.render.border_max_x = float(argv[1])
scn.render.border_min_y = float(argv[2])
scn.render.border_max_y = float(argv[3])

# render a still frame
bpy.ops.render.render(write_still=True)
print("Success.")


The script expects 5 arguments as the console input: - border_min_x - border_max_x - border_min_y - border_max_y - frame number to render

These arguments are parsed and a frame is then rendered and written, when the script is executed.

To call the script with params, add them after two dashes.

Having spaces around -- is important, this is a signal that Blender should stop parsing the arguments and allows you to pass your own arguments to Python.

Then in the command line, execute the following command:

blender -b my_file.blend --python-text script_textblock -- float_min_x float_max_x float_min_y float_max_y int_frame


Example

blender -b my_file.blend --python-text script -- 0.1 0.5 0.2 0.8 1