Script to join sets of 'Linked Flat' faces

I’m trying to make a script that will run through all the faces in a mesh, select all the ‘Linked Flat’ faces, and then join them. I’m getting an error about the context right now:

bpy.context.tool_settings.mesh_select_mode=(False,False,True) #optional
bpy.ops.object.select_all(action=‘DESELECT’)
for ob in bpy.data.objects:
if ob.type == “MESH”:
ob.select = False
m = ob.data
faces = []
for face in m.polygons:
face.select = True
bpy.ops.mesh.faces_select_linked_flat()
bpy.ops.mesh.edge_face_add()
bpy.ops.mesh.select_all(action = ‘DESELECT’)
bpy.ops.object.mode_set(mode = ‘EDIT’)

Any help would be greatly appreciated.

Note that this is exactly what the ‘Limited Dissolve’ tool already does. Did you try this?

Nope, that’s why I’m here in the beginner section… :frowning: But thank you very much! I will check it out! :slight_smile: