1
$\begingroup$

i have a model with multiple materials and i like to change the UV-Map for the texture slot "0" I got it to work with only one material:

import bpy
bpy.data.materials["Wand_Putz_Weiss02.tif"].texture_slots[0].uv_layer = "UVMap"

or like this:

import bpy
bpy.context.object.active_material.texture_slots[0].uv_layer = "UVMap"

is there an way to change the "used uv layer" in all materials assigned to an object? thank you very much for your help!

greetings, simisoad

$\endgroup$
0
$\begingroup$

i got it to work... wrong syntax was the problem :) i not used to program with python.

here is my solution:

import bpy
for item in bpy.data.materials:
     for itextures in item.texture_slots:
        if itextures is not None:
            item.texture_slots[0].uv_layer = "UVMap"
$\endgroup$
  • 1
    $\begingroup$ This will fail when item.texture_slots[0] is None when there is another texture in a latter texture slot. Either just check on item 0 and set if non null, or would need to find first non null texture slot and set that. (The latter would be same as code above, edit last line to itextures.uv_layer = "UVMap" and add a line in if block : break to quit the inner for loop. $\endgroup$ – batFINGER Jun 18 '18 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.