blender/release/scripts/templates/operator_uv.py
Martin Poirier 5b345524ea RNA Types metaclass registration
See mailing list posts for details [1][2][3]

Addons still need to be fixed; Campbell said he'd do it today.

See any of the py files (outside netrender) in this commit for how to do it (it's rather simple).

[1] http://lists.blender.org/pipermail/bf-committers/2010-February/026328.html
[2] http://lists.blender.org/pipermail/bf-committers/2010-August/028311.html
[3] http://lists.blender.org/pipermail/bf-committers/2010-August/028321.html
2010-08-02 02:55:12 +00:00

43 lines
1.0 KiB
Python

import bpy
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.select_uv[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 UV Operator"
def poll(self, context):
obj = context.active_object
return (obj and obj.type == 'MESH')
def execute(self, context):
main(context)
return {'FINISHED'}
if __name__ == "__main__":
bpy.ops.uv.simple_operator()