blender/release/scripts/templates_py/operator_mesh_uv.py
Diptangshu Dey da14a482f2 Fix T90866: Python operator templates are not accessible from menus
Python Operator templates made accessible from respective menus
(required to also use F3 search for quick access)
Also fixed Modal Draw Operator id_name (had duplicate name from other template)

Maniphest Tasks: T90866

Differential Revision: https://developer.blender.org/D13182
2021-11-16 10:45:23 +01:00

55 lines
1.3 KiB
Python

import bpy
import bmesh
def main(context):
obj = context.active_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
uv_layer = bm.loops.layers.uv.verify()
# adjust uv coordinates
for face in bm.faces:
for loop in face.loops:
loop_uv = loop[uv_layer]
# use xy position of the vertex as a uv coordinate
loop_uv.uv = loop.vert.co.xy
bmesh.update_edit_mesh(me)
class UvOperator(bpy.types.Operator):
"""UV Operator description"""
bl_idname = "uv.simple_operator"
bl_label = "Simple UV Operator"
@classmethod
def poll(cls, context):
obj = context.active_object
return obj and obj.type == 'MESH' and obj.mode == 'EDIT'
def execute(self, context):
main(context)
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(UvOperator.bl_idname, text = "Simple UV Operator")
# Register and add to the "UV" menu (required to also use F3 search "Simple UV Operator" for quick access)
def register():
bpy.utils.register_class(UvOperator)
bpy.types.IMAGE_MT_uvs.append(menu_func)
def unregister():
bpy.utils.unregister_class(UvOperator)
bpy.types.IMAGE_MT_uvs.remove(menu_func)
if __name__ == "__main__":
register()
# test call
bpy.ops.uv.simple_operator()