I am trying to create a keymap to scale the selected verts in the UV Editor to zero in the X direction. The code below works correctly in the UV Editor with F3 and find operator "Scale UV selected verts to X=0"
So that's all good.
When I bind a keymap to the space_type 'IMAGE_EDITOR', it shows up as registered in PREFS, but does not execute when I press Shift+Ctrl+X. What am I doing wrong? FWIW, I've tried numerous different key combinations with no success. Thanks for any help.
import bpy
# SCALE X IN UV EDITOR
class OBJECT_OT_scale_xuv(bpy.types.Operator):
"""scales VERTS to x=0"""
bl_idname = "object.vertscale_xuv"
bl_label = "Scale UV selected verts to X=0"
def execute(self, context):
bpy.ops.transform.resize(value=(0, 1, 1), orient_type='VIEW', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)),
orient_matrix_type='VIEW', constraint_axis=(True, False, False),
mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH',
proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
return {'FINISHED'}
addon_keymaps = []
def registerKeymaps():
wm = bpy.context.window_manager
if wm.keyconfigs.addon:
# KEY SHORTCUTS FOR SPACE TYPE IMAGE_EDITOR
km_uv = wm.keyconfigs.addon.keymaps.new(name='Image Editor Tool: Uv, Scale', space_type='IMAGE_EDITOR')
## SCALE UV VERTS X
km_uv_i = km_uv.keymap_items.new('object.vertscale_xuv', 'X', 'PRESS', shift=True, ctrl=True)
addon_keymaps.append((km_uv, km_uv_i))
def unregisterKeymaps():
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
def register():
bpy.utils.register_class(OBJECT_OT_scale_xuv)
registerKeymaps()
def unregister():
unregisterKeymaps()
bpy.utils.unregister_class(OBJECT_OT_scale_xuv)
if __name__ == "__main__":
register()