Using Scripts to Operate Blender?

Sorry if this has been asked or had a guide written for it before, but I simply don’t know the right search terms to use to find this.

I want/need to be able to have one program I (possibly rather badly) made myself control/operate Blender using python scripting. Hopefully without having to have to see blender following the orders my program givens to it. Is this possible?

For example, suppose I want to have my program tell Blender:

  1. to open a blend file
  2. duplicate the active scene 4 times into separate render layers
  3. Alter the new render layers’ materials, textures, render settings, etc separately
  4. Render each layer separately and name each resulting image whatever my program tells it to
  5. Save the resulting images where my program tells it to and then let my program know it has finished

This is all supposed to happen rapidly (not doing any big fancy renders, just basic simple stuff) and hopefully without me needing to see it all happen, though I suppose I can live with having to watch it if running invisibly can’t be done.

I’d heard of scripting languages operating programs before, but know next to nothing about it. Is there any way to get this done?

You should be able to do this via python, which blender supports and has its own python api.

More over, i wouldnt duplicate the active scene 4 times… i would just use python to alter it four times (rendering it each time before changing it again)… and then not saving when closing. Much simplier.

But yes, all of what you are after to do is avaliable via the python api. if you want to start learning python, look below
http://wiki.blender.org/index.php/Doc:2.6/Manual/Extensions/Python/Intro_to_Python
http://wiki.blender.org/index.php/Doc:2.6/Books/Code_snippets_-_Introduction_to_Python_scripting_in_Blender_25


Okay, I think I got the “Compile Bender as Python Module” part done right, but now I have a problem. I can’t figure out the commands.

I can’t, for example, find the right commands to:

  1. Make blender open in the background
  2. Open a blend file at C: estblend.blend
  3. Render the scene to an image at C: estrender.jpg
  4. And then close blender.

I understand enough about programming to get by, I understand enough about Python to do some stuff, but I don’t know the right bpy.whatevers to use to get Blender to do the very very simple things I need to do with it.

I have seen example code that is supposed to show something similar to this, but I can’t get them to work. Could someone show me how it’s done?

You don’t need python at all for that. Just use the commandline: blender c: estblend.blend --background

There are also commandline options to render the scene, but I don’t remember those and I wasn’t able to find the documentation for these options quickly. Maybe try blender --help.