Quads turn into Tris when modifying bpy.data directly


So I am writing a script to non-interactively add new geometry. So rather than going through bpy.ops, which is going to use the currently selected object, I am making a script that creates geometry via bpy.data, so (for example) I can run it from the command line. However, I’m unable to create quads for some reason.

Here is the code:

meshname = ‘mymesh’
mesh = bpy.data.meshes[meshname];
mesh.vertices[0].co = [-1, 1, 0]
mesh.vertices[1].co = [1, 1, 0]
mesh.vertices[2].co = [1, -1, 0]
mesh.vertices[3].co = [-1, -1, 0]

mesh.edges[0].vertices = [0, 1]
mesh.edges[1].vertices = [1, 2]
mesh.edges[2].vertices = [2, 3]
mesh.edges[3].vertices = [3, 0]

mesh.faces[0].vertices = [0, 1, 2, 3]

bpy.data.objects.new(meshname + “_obj”, mesh)
bpy.data.scenes[0].objects.link(bpy.data.objects[meshname + “_obj”])

This should create a simple plane, but it creates a triangle instead. Actually the vertices and edges go where they are supposed to go but the face isn’t a quad, even though I’m setting mesh.faces[0].vertices to a four-element array. It only picks up the first 3 vertices in the polygon, basically. This is blender 2.62. No error message is generated from the script.

Thanks in advance

Not sure exactly what’s going on, but try this reference:

Thanks, I’ll try that.