pythonpython-2.7blenderblender-2.76

Loop doesn't work, 3-lines python code


this question is about blender, python scripting

I'm completely new in this, so please excuse me for any stupid/newbie question/comment.

I made it simple (3 lines code) to make it easy addressing the problem.

what I need is a code that adds a new uv map for each object within loop function.

But this code instead is adding multiple new UV maps to only one object.

import bpy
for x in bpy.context.selected_objects:
    bpy.ops.mesh.uv_texture_add()

what's wrong I'm doing here??

Thanks


Solution

  • The uv_texture_add operator is one that only works on the current active object. You can change the active object by setting scene.objects.active

    import bpy
    for x in bpy.context.selected_objects:
        bpy.context.scene.objects.active = x
        bpy.ops.mesh.uv_texture_add()