This post won’t give you all the information you need if you’re simply new to Blender Scripting. Many of us, however, continued scripting Blender 2.49 because 2.5 scripting wasn’t stable at the beginning. I’m quite sure this post can help you to migrate your scripts from 2.49 although it’s very hands on and I haven’t really tried to organize these useful bits.
- Export script template (source code). This shows how to arrange metadata, invoke the file selector and write simple output to a file (to make sure something’s actually happening). Includes summary instructions to install the script.
I updated my exporter, Ox3ich, although not with all the features of the current 2.49 version. After trying it out a little I will make it available. In the meantime I list just a few of the many differences between the 2.49 / 2.59 APIs.
Writing I/O scripts for Blender 2.5 isn’t exactly what I’d like to do at the moment. I just have to. Scripting integration looks interesting, with a little more flexibility than in 2.4. Useful links…
- Quickstart introduction
- 2.5 Scripting docs (‘from blender 2.5 manual’)
- 2.5 Scripting docs (‘dev’ docs)
- 2.5 Scripting API (‘blender.org’ style)
- 2.5 Scripting API (‘python’ style – this one seems overall better)
- Python 3 docs
- This thread on blenderartists.org provides many 2.5 scripting examples.
As usual, looking at existing scripts will help. The documentation isn’t awesome.
Script Registration
- The registration process has changed. The easy part is updating your metadata (just look at any of the scripts bundled with 2.5).
- Scripts now require register/unregister methods. This allows tighter integration as far as I can see, notably it makes it easy/possible for a script to call another script.
Your script/add-on won’t automatically show in the designated menu, but it should appear under [file > user preferences > add-ons] where you can enable it. Then save user prefs (save as default option in the bottom left) to keep the script enabled next time. This page gives a little information about registering add-ons.
2.49 => 2.59 scripting : Miscellaneous changes
- access current scene - bpy.context.scene
- get object data (e.g mesh) – object.data
- Blender.sys.join => os.path.join
- Writing strings to output stream, see stack overflow answer (python 3.0)
- mesh.verts => mesh.vertices
- faces.verts => face.vertices - additionally, face.vertices is now an array of ints representing vertex indexing.
- face.mat => face.material_index
- mesh.getFromObject => object.to_mesh(bpy.context.scene,True,”PREVIEW”)
- vertex.no => vertex.normal (but still uses vertex.co for ‘coord/coordinate’)
- to change the current frame, use scene.frame_set(). Do not directly assign the frame number. Note that frame numbers start at 0, not 1.
There are changes from Python 2.x to Python 3.x in the way global variables are handled; this combines with a change in the way scripts are invoked, adding up to annoyances when trying a quick and dirty way to output debug info to a file…
Vertex colors
Vertex color data is now separate from face data, stored in Mesh.vertex_colors; additionally this now supports multiple layers, and colors are now in rgb float format (think it used to be rgba, byte format)
- Iterate layers with something like for layer in mesh.vertex_colors
- layer.active to find if a layer is active.
- get layer data: layer.data
- get vertex color for a face: layer.data[i], will contain corner colors for face at index i.
- example 1: mesh.vertex_colors[0].data[1].color4[0]
Red component for corner 4 in face 1, vcol layer 0 of mesh - example 2: mesh.vertex_colors[0].data[0].color1.r
- Red component for corner 1, face 0, vcol layer 0 of mesh
Random links
- A collection of I/O scripts ported from Maya (not sure what this is for)
- Katsbits tutorials (Blender 2.5 tutorials, gaming oriented)

