find and delete edges with no faces...

I’ve done a fair few scripts, but can’t figure out a way to find how many faces an edge is using…

also how can I set the “selection” mode (edge, vertex or face) in edit mode through a script?

here’s an explanation of what I’'m trying to do…
I’m doing a project thet needs to be exported to Maya on a regular basis… Maya doesn’t support edges without faces and will crash and die horribly when using cgfx shaders on these “degenerates” (cgfx is core to the project so cannot be avoided)… the troubles is that my scenes are quite large with many hundreds of objects so finding the cuprit that is causing maya to crash is pretty hard… because maya doesn’t suppport these edges, but they are imported via FBX format there’s no way to clean this up in maya…

I really need to write a script in blender to remove all “free” edges from hundreds of objects…(or at least tell me that some objects have “free edges” and tellme which they are!.. (by “free” i mean an edge that is not part of any face… though it may share vertices with other edges…)

I can do it manually by using:
select—>non-triangles/quads in edit mode and then deleting the edges… but again, this isn’t really feasable on this quantity of stuff…

Any help will be appreciated!

You can set the selectionmode with Mesh.mode (doc).

Blender doesn’t keep track of the number of faces that use an edge, so you’ll have to generate that information yourself. A good example can be found here.

And here’s a script that does what you want:

import bpy
import Blender

scn =
clean = []

for ob in scn.objects:
    if ob.type != 'Mesh':
    me = ob.getData(mesh=True)
    edge_faces = dict([(ed.key, [0, ed.index]) for ed in me.edges])
    for f in me.faces:
        for key in f.edge_keys:
            edge_faces[key][0] += 1
    zero_faces = [i[1][1] for i in filter(lambda i: i[1][0] == 0, edge_faces.items())]
    if len(zero_faces)>0:
        clean.append([, len(zero_faces)])

if len(clean)>0:
    print "Cleaned %i objects"%len(clean)
    for i in clean:
        print i[0]+": "+str(i[1])+" edges"


Warning! Somehow the edges.delete() function also deletes faces that only share 1 vertex with the edge that is removed. This might not be a problem for you, but it probably is. In that case you can decide for yourself what you want to do with the edges that cause trouble (they are stored in the zero_faces variable).

Thank you very much, That’s great!

your doc is a bit outdated, use this instead :
and this one for the game engine :