Here is another script which relies more on Blender's built-in methods to retrieve the values. This version has the advantage to still run very fast with bigger meshes. For an object with 100000 faces this script takes around 0.5 seconds while @Erdorano's version needs around 25 seconds on my machine.
Usage: select one face of an object and run the script. Doesn't matter if the object is in Edit or Object mode, only needs to be selected.
import bpy
# get the selected object in edit mode
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.editmode_toggle()
obj = bpy.context.active_object
# get face index
old_face_index = -1
for poly in obj.data.polygons:
if poly.select:
old_face_index = poly.index
break
# compute new face index
material_index = obj.data.polygons[old_face_index].material_index
new_face_index = -1
for poly in obj.data.polygons:
if poly.material_index == material_index:
new_face_index += 1
if poly.select:
break
# create a duplicate
bpy.ops.object.editmode_toggle()
bpy.ops.object.duplicate()
temporary_obj = bpy.context.object
temporary_obj.name = "temporary" # choose a name which does not exist in the scene
# separate all faces with face material
bpy.ops.object.editmode_toggle()
temporary_obj.data.polygons[old_face_index].select = True
bpy.ops.mesh.select_similar(type='MATERIAL')
bpy.ops.mesh.separate(type='SELECTED')
# select the separated mesh
bpy.ops.object.editmode_toggle()
bpy.ops.object.select_all(action='DESELECT')
temporary_obj001 = bpy.data.objects['temporary.001']
temporary_obj001.select_set(True)
# select the same face in the separated mesh and read the vertex data
temporary_obj001.data.polygons[new_face_index].select = True
bpy.ops.object.editmode_toggle()
new_vertex_indices = [ v for v in temporary_obj001.data.polygons[new_face_index].vertices ]
# we got all we want
print(
'\nselected face index:', old_face_index,
'\nnew face index:', new_face_index,
'\nnew vertex indices:', new_vertex_indices
)
# delete temporary objects
bpy.ops.object.editmode_toggle()
tmp_mesh = temporary_obj.data
tmp_mesh001 = temporary_obj001.data
temporary_obj.select_set(True)
bpy.ops.object.delete(confirm=False) # delete from outliner
bpy.data.meshes.remove(tmp_mesh) # delete from orphaned data
bpy.data.meshes.remove(tmp_mesh001) # delete from orphaned data