Rendering Animation in Background

Hello There, my name is Vinicius, i’m new here and in python scripting for blender.

I’m using this code to render animation in background mode (blender -b -P C:\blender\python\

render = sce.getRenderingContext()
render.extensions= True
render.renderPath = render_path
render.imageType = Render.AVIRAW
render.sFrame= 1
render.eFrame= 61

But it doesn’t work. Only the first frame is rendered, how can I solve this?

i am not sure and not able to test right now but i think you might need to add a “-a” to your command to tell blender to render an animation…check with the command line help (-h) where to place it, if i remember well it has to be after the -b.
maybe it helps

Thanks for answering oenvoyage, my problem is almost the same discussed in this thread:

The difference is that in my case I dont want to open a blender file, what I want to do is:

  • Receive a text parameter
  • Create the objects (text3D, camera, light)
  • create an animation …
  • render the animation

And I want to do that without needing to save a file .blend

The code is as follows:

import Blender
import bpy
from Blender import Camera, Curve, Object, Scene, Text3d, Text
from Blender.Scene import Render

def example_function(body_text, save_path, render_path):



cam_data= Camera.New(‘persp’, ‘MyCam’) # create new camera data
cam_ob= # add the camera data to the scene (creating a new object) cam_ob # set the active camera
cam_ob.loc= 0,0,10

txt_data=‘MyText’, ‘Text3d’)

Text Object

txt_ob = # add the data to the scene as an object
txt_data.setText(body_text) # set the body text to the command line arg given
txt_data.setAlignment(Blender.Text3d.MIDDLE)# center text


lamp_ob.loc= 2,2,5

Create the key-frames | Cria os quadros-chave

Blender.Set(“curframe”, 1)
Blender.Set(“curframe”, 31)
Blender.Set(“curframe”, 61)
Blender.Set(“curframe”, 1)

Ajust the animation size | Ajusta o tamanho da animacao


if save_path:
f= open(save_path, ‘w’)
ok= True
print ‘Cannot save to path “%s”’ % save_path
ok= False

if ok:
Blender.Save(save_path, 1)

if render_path:

render = sce.getRenderingContext()
render.extensions= True
render.renderPath = render_path
render.imageType = Render.AVIRAW
render.sFrame= 1
render.eFrame= 61

Using the suggestion of the guy on the thread and adding the ‘-a’ option to the command line dont solve the issue:

blender -b -P -a C:\blender\python\ – --text=“Hello World” --render="/tmp/hello" --save="/tmp/hello.blend"

Any suggestions?

Thanks a lot

Thanks oenvoyage …
it works …
but it does only if I run an .blend file, like in the command: blender -b -a file.blend, but what i want to do is something like -> blender -b -a -P
The ‘’ is where I create all the objects and the animation, then I call the function to render that animation, but dont work …

Any suggestions?