When you say "the first mesh", I think you mean the first shell? Your script only runs on one mesh, but appears to be trying to deal with the mesh one shell at a time.
Have you confirmed you script is correctly finding the shells? I can't tell, by reading it. If the polygons are correct for the first shell, but not correct after that, then I expect the problem is in the script that separates the face indices into shells.
Here is a different version. I think it should do the same thing yours is intended to do. It's written using API 2.0 so might require a few changes.
def mesh_to_shells(dp_node):
""" Returns a list of lists of face IDs. """
mfn_mesh = OpenMaya.MFnMesh(dp_node)
mit_poly = om.MItMeshPolygon(dp_node)
shells = []
already_sorted = set()
for id in range(mfn_mesh.numPolygons()):
if id in already_sorted:
continue
this_shell = [id]
# Starting with a single face, we keep adding connected face IDs to
# the end of the list, until we can't find any new ones.
id_within_shell = 0
while id_within_shell < len(this_shell):
mit_poly.setIndex(this_shell[id_within_shell])
id_within_shell += 1
connected_IDs = set(mit_poly.getConnectedFaces())
connected_IDs -= set(this_shell)
this_shell.extend(connected_IDs)
shells.append(this_shell)
already_sorted |= set(this_shell)
return shells