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\background.py):

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

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

Hello,
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: http://blenderartists.org/forum/showthread.php?t=92476

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):

sce= bpy.data.scenes.active

Camera

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

txt_data= bpy.data.curves.new(‘MyText’, ‘Text3d’)

Text Object

txt_ob = sce.objects.new(txt_data) # 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
txt_data.setExtrudeDepth(1.0)

Lamp

lamp_data= bpy.data.lamps.new(‘MyLamp’)
lamp_ob= sce.objects.new(lamp_data)
lamp_ob.loc= 2,2,5

Create the key-frames | Cria os quadros-chave

Blender.Set(“curframe”, 1)
txt_ob.insertIpoKey(Blender.Object.LOC)
Blender.Set(“curframe”, 31)
txt_ob.setLocation(-5,0,0)
txt_ob.insertIpoKey(Blender.Object.LOC)
Blender.Set(“curframe”, 61)
txt_ob.setLocation(5,0,0)
txt_ob.insertIpoKey(Blender.Object.LOC)
Blender.Set(“curframe”, 1)

Ajust the animation size | Ajusta o tamanho da animacao

sce.getRenderingContext().endFrame(61)

if save_path:
try:
f= open(save_path, ‘w’)
f.close()
ok= True
except:
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.sizePreset(Render.PC)
render.imageType = Render.AVIRAW
render.sFrame= 1
render.eFrame= 61
render.renderAnim()

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\background.py – --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 script.py
The ‘script.py’ is where I create all the objects and the animation, then I call the function to render that animation, but dont work …

Any suggestions?