Set displayed texture through script

Heya,
Im making an import script of models that use multitexturing.
First i imported it as a unique mesh, textures worked for rendering but it seems blender cannot display multi texture in viewport…

can you confirm it really doesnt, I would be sad to have to split the model to get correct viewport display :confused:

If it doesn’t, I would have to split the model, but anyway I cant find any API to set the texture displayed in the viewport, do u guys know how can i achieve this?

The textures im talking about are image textures mapped through UV coordinates.

Thanx :slight_smile:

You mean Viewport Shading: Textured?

import bpy

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        area.spaces[0].viewport_shade = 'TEXTURED'


no i mean, when the viewport is in textured view,
the texture displayed on the mesh is not the one from the assigned material’s texture, but the one selected in the UV/image editor when editing UV.

How to change this image displayed on the mesh?

solved it by myself finally,
here is what I did :


uv1 = mesh.uv_textures.new("UVMap")
uv_layer1 = mesh.uv_layers[0]

# add uv coordinates
for i in range(len(uv_layer1.data)):
    uv_layer1.data[i].uv = texCoords[mesh.loops[i].vertex_index]

# set displayed texture for each face
for i in range(faceCount):
    uv1.data[i].image = img

not really intuitive but it works ! thx for your answer CoDEmanX