How do I grab the active texture on a face in python? So I'm pretty much done with designing a script to export meshes I (or others within my group) make in Blender for use in another piece of software (VoxelStudio).

Everything has been slow going due to a serious lack of documentation/examples, but I have to say these forums have been a god send, thank you people.

The one last part that's really stopping me from actually finishing the script is working out how to get the ID number of the Texture that's applied to a given material on a given Face.

I can get the active material easily enough.... though that took trawling everywhere to work out how. How do I get the active materials active texture for the current face?

For example:

for i in context.selected_objects:
        i.update_from_editmode( )
        tempmesh = bmesh.new( )
        tempmesh.from_mesh( i.data )
        for f in tempmesh.faces:
            mat = i.material_slots[f.material_index].material
            writeString ( file, '%i\r\n' % ( f.material_index ) )
        tempmesh.free


You can see that I've got the material index easily enough, and the material itself is held in 'mat' within the 'for f' loop. However, the method of working out what the texture index of the current face is still eludes me.

The model is set up with different Materials having multiple textures assigned, each for different purposes. Just no idea how to ask, what texture is showing on this material on that face.
This script will print the names of the the textures assigned to the various materials on the selected objects:

import bpy, bmesh

C = bpy.context
for o in C.selected_objects:
        bm = bmesh.new()
        bm.from_mesh( o.data )
        for f in bm.faces:
            mat = o.material_slots[ f.material_index ].material
            if C.scene.render.engine == 'BLENDER_RENDER':
                for textureName in [ ts.texture.name for ts in mat.texture_slots if ts ]:
                    print( "material_index_{mi}.texture_name_{tn}".format( 
                        mi = f.material_index,
                        tn = textureName
                    ) )
            if C.scene.render.engine == 'CYCLES':
                for textureName in [ n.name for n in mat.node_tree.nodes if 'TEX' in n.type ]:
                    print( "material_index_{mi}.texture_name_{tn}".format( 
                        mi = f.material_index,
                        tn = textureName
                    ) )                    
        bm.free


It will print it in the format of "material_index_X.texture_name_Y" (where X is the material index, and Y is the texture name).

You can of course use the texture slot index, rather than the texture name. Or what might be even more intersting, the image path assigned to the image texture you might be using (accessible through texture.image.filepath).