5
obj = context.active_object
8
is_editmode = (obj.mode == 'EDIT')
10
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
12
if not mesh.uv_textures:
13
uvtex = bpy.ops.mesh.uv_texture_add()
15
uvtex = mesh.uv_textures.active
18
for i, uv in enumerate(uvtex.data):
19
uvs = uv.uv1, uv.uv2, uv.uv3, uv.uv4
20
for j, v_idx in enumerate(mesh.faces[i].vertices):
22
# apply the location of the vertex as a UV
23
uvs[j][:] = mesh.vertices[v_idx].co.xy
26
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
29
class UvOperator(bpy.types.Operator):
30
'''UV Operator description'''
31
bl_idname = "uv.simple_operator"
32
bl_label = "Simple UV Operator"
35
def poll(cls, context):
36
obj = context.active_object
37
return (obj and obj.type == 'MESH')
39
def execute(self, context):
45
bpy.utils.register_class(UvOperator)
49
bpy.utils.unregister_class(UvOperator)
52
if __name__ == "__main__":
56
bpy.ops.uv.simple_operator()