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