Can I automate Blender importing and rendering large numbers of files?

Harley wrote “you just have to write a python script that looks at the your custom params specifying your X3D (or whatever), imports it […]” Thank you; I have gone back to work on the “imports it” step.

Both before and after posting here I got nowhere on the “imports it” step using the Blender Python API docs. The Blender Python API seems to support implementing import operations in terms of low level abstractions (e.g. operating on a mesh) as in http://vrm.ao2.it/ and http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Advanced_Tutorials/Python_Scripting/Import_scripts but it does not seem to support executing Blender’s high level commands without GUI input. I don’t really want to implement X3D import in terms of low level abstractions: the implementation has already been done inside Blender, and I’d prefer to reuse that.

After posting here, I did some more searching and found that a question similar to mine was asked and answered at http://blenderartists.org/forum/archive/index.php/t-159500.html . I have now adapted that answer to something that seems to work for me. I’ll summarize my adaptation here in hopes that it might help someone else with a similar question someday, as the summary answer from “harwen” has helped me.

The method “harwen” used to invoke Blender’s own import-it functionality (which is the method I use too) does not seem to be documented anywhere. It’s probably not supported either, so beware.

Also beware that 2.49b import_web3d imports only a rather smaller subset of VRML than the documentation at http://wiki.blender.org/index.php/Extensions:2.4/Py/Scripts/Import/X3D_VRML97 might make you think. (Smaller than it made me think…) You should probably discount text like “this importer should be able to load scenes generated from other 3D software” and skip to the listed subset of things that it actually does support. E.g., it’s not going import Extrusion for you, or anything with 2D in the name. Then perhaps discount that list further because IndexedFaceSet, its way of importing mesh-y data, seems not to work reliably. (I was unable to get it to import triangle faces except by duplicating a vertex of each triangle face so that it thinks it is a rectangle face, which I had already discovered it can import.)

Anyway. If that doesn’t discourage you too much, then here’s how I was able to get Blender 2.49b on the Linux command line to render a recognizable subset of a car.wrl VRML demo which I found on the net, apparently using the reader which is built into Blender and certainly without having to implement a reader myself:

  1. Write four lines of Python into a script autoimport-x3d.py:
    import sys
    sys.path.append(r’/usr/share/blender/scripts/blender/’)
    import import_web3d
    import_web3d.load_web3d(‘car.wrl’)
    (For all I know, your internal Blender scripts might not be installed in the same place mine are installed, in which case my sys.path.append command won’t work for you. On a Unix system you can probably find the scripts quickly using the command ‘locate import_web3d’; then adjust your sys.path.append command accordingly.)

  2. Interactively run Blender to set up camera angles and lighting and so forth which will be suitable for rendering your imported scenes. Save the Blender session as stage.blend.

  3. Run blender from the command line as
    blender -b stage.blend -P autoimport-x3d.py -o //car -F JPEG -x 1 -f 1
    et voila (?): for me, at least, this renders the car.wrl scene into
    car0001.jpg with no GUI mousing and clicking required.