Im trying to add a uv map via python and not having any luck.
Im on 2.80. Im getting the selected object, getting the mesh, then trying to add a second uv channel with ‘bpy.ops.mesh.uv_texture_add()’ as per the documentation:
https://docs.blender.org/api/blender2.8/bpy.ops.mesh.html?highlight=uv_texture#bpy.ops.mesh.uv_texture_add
I get the following error:
Operator bpy.ops.mesh.uv_texture_add.poll() failed, context is incorrect
selected = bpy.context.active_object if selected == "" or selected is None: self.report({'ERROR'},"please select a mesh") return {"FINISHED"} #vcol_data = selected.vertex_colors.active.data mesh = selected.data ''' for uv_layer in mesh.uv_layers: for tri in mesh.loop_triangles: for loop_index in tri.loops: print(uv_layer.data[loop_index].uv) ''' #bpy.ops.object.mode_set(mode='EDIT') #bm = bmesh.from_edit_mesh(mesh) print(mesh) print(len(mesh.uv_layers)) # check for second uv channel if len(mesh.uv_layers) < 2: #mesh.uv_textures.new() #mesh.uv_texture_add() #bm.uv_textures.new() bpy.ops.mesh.uv_texture_add() # copy verts[1][0] to uv[1][0] # copy verts[2][0] to uv[1][1] ''' uv_lay = bm.loops.layers.uv.active for face in mesh.faces: for loop in face.loops: uv = loop[0].uv print("Loop UV: %f, %f" % uv[:]) vert = loop.vert print("Loop Vert: (%f,%f,%f)" % vert.co[:]) ''' return {"FINISHED"}