How to render an object - command line

I would like to create a python script that imports a 3d module, such as ‘3ds’, move and tilt the camera based on input parameters, then render the scene all from a command line. Please let me know if you can help, thanks.

Here is the bat file
“C:\Program Files (x86)\Blender Foundation\Blender\Blender.exe” -b -P test.py

Here is test.py

import Blender
from Blender import *
#Don’t know how to import
#load_3ds(‘C:\Temp\RenderEngine\Modules\fw33_3ds\fachwerk33T.3ds’);

sc=Scene.GetCurrent()
#Doesn’t work
camera = sc.objects.camera

#Need to get input parameters here
#Need to figure out how to move and rotate camera here.

context = sc.getRenderingContext()
context.render()
context.extensions = True
context.saveRenderedImage(“Test.jpg”)
Blender.Scene.Render.CloseRenderWindow()

Here is the latest. I will most likely use a file to send the arguments. Still working on how to use the 3ds importer and moving the camera.

import sys
import Blender
from Blender import *
#import 3ds_import
#load_3ds(‘C:\Temp\RenderEngine\Modules\fw33_3ds\fachwerk33T.3ds’);
sc=Scene.GetCurrent()
camera = Camera.New()
sc.objects.new(camera)
camera.shiftX = camera.shiftX + 2;
camera.shiftX = camera.shiftY + 2;
print camera.angle
print camera.shiftX
print camera.shiftY

context = sc.getRenderingContext()
context.setImageType(Scene.Render.JPEG)
context.extensions = True
context.renderPath = ‘C:\Temp\RenderEngine\Cam’
context.renderAnim()
Blender.Scene.Render.CloseRenderWindow()

OK first you need to rename Blender/.blender/scripts/3ds_import.py to import_3ds.py.

In your script do the following.

from import_3ds import load_3ds

load_3ds("pat/to/file.3ds",False) #false suppresses the import GUI and makes the script import the mesh only AFAICT.

If you need to import other objects too you will need to take a look at the script and edit the load_3ds function.

As for rotating the camera, i have no idea how to do it. I am lacking the math skills.

Here is how you set a camera position, now just need to figure out a good way to point the camera.

camera = Camera.New()
ob = sc.objects.new(camera)
ob.setLocation(0.0, 0.0, 2.0)
print ob.getMatrix()

I had to change the bat file to include a blank blend file. Seems chessy, but I guess I’ll live with it.

“C:\Program Files (x86)\Blender Foundation\Blender\Blender.exe” -b render_cameras.blend -P render_cameras.py