I’m struggling with a little problem. I am trying to use the python api to change the active texture.
Being naive, I just say
obj.data.uv_textures.active=uvmap_target
where uvmap_target is a MeshTexturePolyLayer
However, this doesn’t actually change the active uv_texture, so apparently, uv_textures.active is readonly. I have tried changing it both while being in object mode and being in edit mode, but neither works.
I see that you are doing this in the console. I am doing this in an operator and I am using the context that comes as an argument to the operator as opposed to the global bpy.context. Could this be an issue?
Hmm. Perhaps I’m overlooking something. I will try and see what goes wrong tonight and let you know how I screwed up. Thanks once again. You will get a big acknowledgement when I get this addon working the way I want to…
I got it working. For some reason the way I did it (obj.data.uv_textures.active=uvmap_target), does not work, but if I follow your way directly, it does work. So changing the active texture of a certain object should be done, but rather, the bpy.context.object.data.uv_textures should be used. So thanks again! My script now works!
It shouldn’t matter whether you use bpy.context.object or an object reference to retrieved earlier. It must use a uv texture of that object however, maybe you tried to assign a uv texture reference from another object?
I have only one object in the test scene, so that is unlikely. If you want I can try to isolate the problem further. Right now I’m just happy that it works in my code, but I can easily produce a version that does not work. As said, it seems to only occur when doing this in an operator. If you say it shouldn’t matter, I’m either doing something wrong somewhere else, or I have clumsely stumbled upon a bug.