~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/templates/operator_uv.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import bpy
2
 
 
3
 
 
4
 
def main(context):
5
 
    obj = context.active_object
6
 
    mesh = obj.data
7
 
 
8
 
    is_editmode = (obj.mode == 'EDIT')
9
 
    if is_editmode:
10
 
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
11
 
 
12
 
    if not mesh.uv_textures:
13
 
        uvtex = bpy.ops.mesh.uv_texture_add()
14
 
    else:
15
 
        uvtex = mesh.uv_textures.active
16
 
 
17
 
    # adjust UVs
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):
21
 
            if uv.select_uv[j]:
22
 
                # apply the location of the vertex as a UV
23
 
                uvs[j][:] = mesh.vertices[v_idx].co.xy
24
 
 
25
 
    if is_editmode:
26
 
        bpy.ops.object.mode_set(mode='EDIT', toggle=False)
27
 
 
28
 
 
29
 
class UvOperator(bpy.types.Operator):
30
 
    '''UV Operator description'''
31
 
    bl_idname = "uv.simple_operator"
32
 
    bl_label = "Simple UV Operator"
33
 
 
34
 
    @classmethod
35
 
    def poll(cls, context):
36
 
        obj = context.active_object
37
 
        return (obj and obj.type == 'MESH')
38
 
 
39
 
    def execute(self, context):
40
 
        main(context)
41
 
        return {'FINISHED'}
42
 
 
43
 
 
44
 
def register():
45
 
    bpy.utils.register_class(UvOperator)
46
 
 
47
 
 
48
 
def unregister():
49
 
    bpy.utils.unregister_class(UvOperator)
50
 
 
51
 
 
52
 
if __name__ == "__main__":
53
 
    register()
54
 
 
55
 
    # test call
56
 
    bpy.ops.uv.simple_operator()