diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-01-14 13:50:58 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-01-14 13:50:58 +0300 |
commit | 9de67b8ca9247be79b91450e98a18464c39a052b (patch) | |
tree | d058aadf1cc70c97f859dfa45dae4d5705eddbe9 /release | |
parent | fffbb2c7ebb2b7d3a0c20e9b04fa4132a070afb3 (diff) |
UV operator template
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/templates/operator_uv.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/release/scripts/templates/operator_uv.py b/release/scripts/templates/operator_uv.py new file mode 100644 index 00000000000..737059ab666 --- /dev/null +++ b/release/scripts/templates/operator_uv.py @@ -0,0 +1,42 @@ + +def main(context): + obj = context.active_object + mesh = obj.data + + is_editmode = (obj.mode == 'EDIT') + if is_editmode: + bpy.ops.object.mode_set(mode='OBJECT', toggle=False) + + + if not mesh.active_uv_texture: + bpy.ops.mesh.uv_texture_add() + + # adjust UVs + for i, uv in enumerate(mesh.active_uv_texture.data): + uvs = uv.uv1, uv.uv2, uv.uv3, uv.uv4 + for j, v_idx in enumerate(mesh.faces[i].verts): + if uv.uv_selected[j]: + # apply the location of the vertex as a UV + uvs[j][:] = mesh.verts[v_idx].co.xy + + + if is_editmode: + bpy.ops.object.mode_set(mode='EDIT', toggle=False) + +class UvOperator(bpy.types.Operator): + '''''' + bl_idname = "uv.simple_operator" + bl_label = "Simple Object Operator" + + def poll(self, context): + obj = context.active_object + return (obj and obj.type == 'MESH') + + def execute(self, context): + main(context) + return {'FINISHED'} + +bpy.types.register(UvOperator) + +if __name__ == "__main__": + bpy.ops.uv.simple_operator() |