[Bf-python] Automating tasks in blender via blender --python script.py

Rodrigo Benenson rodrigo.benenson at gmail.com
Wed May 2 13:59:45 CEST 2012


Dear Blender mailing list,

I just spent 3 hours on the blender IRC trying to figure out how to
automate a specific task using a python script called via "blender
--python script.py".

The purpose of the script is to open a blender file, apply some
operations and save the new blender file.
This must be done without any click from the user, so that the process
can be called via command line (i.e. as part of a bigger system).

Quite rapidly I entered into "context hell" trying to figure out the
proper context to call "bpy.ops.graph.select_all_toggle();
bpy.ops.graph.sample()".
The answer to this was "the_scene.objects.active = the_object;
bpy.context.area.type='GRAPH_EDITOR' " (found by someone in the IRC 2
hours after my first attempt).

The key problem now is that when running via  "blender --python
script.py" bpy.context.area is None, this seems to be a consequence of
bpy.context.window being None.

>From what I could gather in the IRC, no one is aware of a method to
create a new window (or setup properly the bpy.context.area) from
python.
In this case the documentation is of no help (it does not even mention
bpy.context.area).

Being able to launch automated tasks via "blender --python script.py"
seems like a natural usage of this feature, and has multiple use
cases.

Does any one have a suggestion/idea on how we could make this work ?

Thanks for your input.
Best regards,
rodrigob.



More information about the Bf-python mailing list