Python scripting - modifying mesh - help requested

I’m having some problems writing a script to edit a mesh. I’m basing it on the model mesh edit script (in particular, I am using Mesh not NMesh). The problem is that it does not seem to actually do anything to the mesh; after I have run the script everything as it was before. Running Blender.Refresh() does not change the result. Is there anything else that I need to do?

Can you post the code you have? Either as a .py file somewhere, or wrapped in [ code ] tags here?

Here is the working function; all the rest follows the model script that comes with Blender.

def my_mesh_util(mesh):
    selVerts = mesh.verts.selected()
    merges = []
    for i in selVerts:
        for j in selVerts:
            if i < j:
                v1 = mesh.verts[i]
                v2 = mesh.verts[j]
                dist = sqrt((v1.co[0]-v2.co[0])**2 + (v1.co[1]-v2.co[1])**2 + (v1.co[1]-v2.co[1])**2)
                if dist < 0.01:
                    merges.append([i, j])
    for m in merges:
        mesh.verts[m[0]].co = mesh.verts[m[1]].co
    mesh.update()
    Blender.Redraw()

I may be mistaken, but this seems to me a function that does nothing, except to make vertices occupy exactly the same spot if they are already very close to another . The number of vertices remains the same.

That’s what it’s supposed to do… but actually the vertexes don’t move. (Once the vertexes are in the same place, I can remove the duplicates).

Rewritten script works for me, you sure:

  1. The distance calculation isn’t throwing things off.
    Correct version:

v1=mesh.verts[i].co
v2=mesh.verts[j].co
if (v1-v2).length<dist:
    #blah

  1. You have selected vertices in the mesh?

What’s in the merges list after being built? [Please tell me you checked before posting]

Again, can you post all the code? Without it I can’t test YOUR code easily. The problem may lie elsewhere/the way things are structured. More of a general point this one, when asking for help with code, it’s often helpful to have a link to the whole script for testing.