Quad Faces Rejected when Building Mesh

I’m working on a from scratch mesh building script I want to convert from 2.49 to 2.5. The script works as far as putting in the verts and the 2 triangles but then dies when it tries to create quad faces.

File “triforce25_wip.py”, line 46, in <module>
ValueError: StructRNA -
item.attr = val: MeshFace.verts: array length cannot be
changed to 4

Is there a workarround that anyone knows for this?


bpy.ops.object.add( type="MESH" )
triforceOb = bpy.context.object
tforceData = triforceOb.data

# vert buffer phase
floorVerts = [0, 0, 0], [1, 0, 0], [0.5, 1, 0]
ceilingVerts = [0, 0, .2], [1, 0, 0.2], [0.5, 1, 0.2]
vertBuffer = []
vertBuffer.extend( floorVerts )
vertBuffer.extend( ceilingVerts )

# face buffer setup
topTri = [0,1,2]
bottomTri = [3,4,5]
baseQuad = [0,3,4,1]
leftQuad = [0,3,5,2]
rightQuad = [1,4,5,2]
faceBuffer = []

faceBuffer.append( topTri )
faceBuffer.append( bottomTri)
faceBuffer.append( baseQuad )
faceBuffer.append( leftQuad )
faceBuffer.append( rightQuad )

tforceData.add_geometry( verts=6, edges=0, faces=5 )

# add the vertices
i = 0
while i &lt; len( vertBuffer ):
    tforceData.verts[i].co = vertBuffer[i]
    i = i + 1

# add the faces.  Dies when it tries to add a 4 sided shape.
i =0
while i &lt; len( faceBuffer ):
    print( "adding buffer: " + str( faceBuffer[i] ) )
    tforceData.faces[i].verts = faceBuffer[i]
    i = i + 1

In 2.50 you need the mesh.add_geometry() and mesh.verts.foreach_set() / mesh.faces.foreach_set() methods. See this thread http://blenderartists.org/forum/showthread.php?p=1547370#post1547370 for a working example with comments.

That thread wasn’t the whole answer for me. However, I did solve it. Your flattening function script for verts ( from your gears script ) was really handy.

However, that wasn’t going to help me with the list unpacking I needed to do for my face list. Learned about unpack_face_list over hereand found the actual script here.

So it works but it scares me a little. I aim to use this in a tutorial and it looks a lot harder to explain than mesh building under the 2.4x system.