Fail to join faces with python
okay so here is the information I can give you:


bmesh.utils.face_join(faces, remove=True) only works (in my tests) if the faces you provide are actually connected by an edge. If there is any other face involved that is not connected, the function will fail. This is the problem you are experiencing


therefore you need to programmatically select linked faces. (see 3.)


The indexes for the vertices are not guaranteed to be the same indexes. So range(4, 7) in your code in bmesh does not necessarily give you the same vertices you added earlier to the mesh.


I suggest, you add the face the same way you add the vertices, to the mesh datablock. Or, better, you should add the vertices to the bmesh like this:

v1 = bm.verts.new((2.0, 2.0, 2.0))
v2 = bm.verts.new((-2.0, 2.0, 2.0))
v3 = bm.verts.new((-2.0, -2.0, 2.0))

new_face = bm.faces.new((v1, v2, v3))


Edit: your new face might actually not share an edge with the existing faces. you should check that probably


Now that you have your face properly set up, you can try to feed linked faces into the bmesh.utils.face_join(linked_faces)


this is a function i wrote to get linked faces:

def get_linked_faces(f):

    if f.tag:
        return []

    f_linked = [f]
    f.tag = True
    # Select edges that link two faces
    edges = [e for e in f.edges if len(e.link_faces) == 2]
    for e in edges:
        faces = [elem for elem in e.link_faces if not elem.tag]

        if not len(faces) == 0:
            for elem in faces:
                f_linked.extend(get_linked_faces(elem))

    return f_linked


you will get an array of linked face groups:

f_link_map = []
for face in bm.faces:
    if not face.tag:
        linked_faces = get_linked_faces(face)
        f_link_map.append(linked_faces)



in the end of your operations it's also good practise to add

bm.free()


i hope that helps you. it took me quite a while to find out what the problem is in your case. also sorry, python formatting is quite an annoyance.