access['imgname.png'] from object (blender 2.66.1)

Hi all,
my question is quite simple. i need to find the name of the texture applied to a model. the image name is showed on the structure[“imgname.png”], the users property equals 1. this means that the image is used.
How to build my scenario.

  1. add a model (cube or whatever)
  2. unwrap textures
  3. on the uv image editor panel image ->open image
  4. on 3d view, viewport shading texture
    and the texture should appear on the model.

I have a scene with different models, with different textures (usually 1 texture for model).
In my custom exporter i have to cycle on models and save the texture name.


just to make sure: you really want to know only the name of what blender calls “texture” right? Not image name, not material name, not any kind of filepath, just texture name?

Well there’s a general problem with blender, you assign images in uv editor, but textures in material tab.

This gives for example the uv-editor assigned image of the first face:

>>>[0].image[‘cube loops.png’]

and this the material index as assigned in the material tab:

And this uses the index to find one of the texture names (texture “Tex”)
>>> me =
>>> me.materials[me.polygons[0].material_index].texture_slots[‘Tex’].name

You may look at the export scripts, e.g. OBJ, or here is my blender-cod export script:

(search for “material” to see where it handles them)

Hi! thank you for your promptly and complete response. You showed me the right way: what i wanted to achieve was exactly:

for obj_to_process in obj_to_export:
    if[0] is not None:        myscriptclass.add_texture([0]

This almost works, but in a test i just did i had:




Now in the 3dView the image visible is ‘crayons-xchng.jpg’, that is the one i opened from the uv_editor. What is the criteria to choose the index of data correctly to have a WYSIWYG behaviour?

by the way, from[2].image to[30].image i found[‘crayons-xchng.jpg’]


PS. it seems that the vector data contains info relative to faces, so you can have different images for different faces. This solves my question above.