1
$\begingroup$

I struggle understanding how to properly overwrite Blender's default keys.

Here are two PIE keyconfigs. S works perfect. But A does not work. I have to add SHIFt ALT and such to overwrite default S.

    #Pie Transform
    km = wm.keyconfigs.addon.keymaps.new(name='Object Non-modal')
    kmi = km.keymap_items.new('wm.call_menu_pie', 'S', 'PRESS')
    kmi.properties.name = "pie.transform"

    #Pie Select
    km = wm.keyconfigs.addon.keymaps.new(name='Object Non-modal')
    kmi = km.keymap_items.new('wm.call_menu_pie', 'A', 'PRESS', shift=True, alt=True)
    kmi.properties.name = "pie.select"

Here are the Pie definitions.

# PIE TRANSFORMATION -------------------------------------------------------------------
class PieTransform(Menu):
    bl_idname = "pie.transform"
    bl_label = "Transformation"

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()

        if context.active_object:
            if(context.mode == 'EDIT_MESH'):
                #4 - LEFT
                pie.operator("transform.translate", text="Move") 
                #6 - RIGHT
                pie.operator("transform.shrink_fatten")
                #2 - BOTTOM
                box = pie.split().column()
                box.operator("view3d.snap_cursor_to_selected")
                box.operator("wm.call_menu", text="Snap Menu").name="VIEW3D_MT_snap"
                box.separator()
                box.operator("transform.mirror")
                box.separator()
                box.operator("align.x", text="Align X")
                box.operator("align.y", text="Align y")
                box.operator("align.z", text="Align Z")
                #8 - TOP
                pie.operator("transform.rotate", text="Rotate") 
                #7 - TOP - LEFT 
                pie.operator("transform.resize", text="Scale")
                #9 - TOP - RIGHT
                pie.operator("transform.shear")
                #1 - BOTTOM - LEFT
                pie.operator("pivotpoint.type", text="Pivot Bounding Box").variable = 'BOUNDING_BOX_CENTER'
                #3 - BOTTOM - RIGHT
                pie.operator("pivotpoint.type", text="Pivot 3D Cursor").variable = 'CURSOR'
            else:

                #4 - LEFT
                pie.operator("transform.translate", text="Move") 
                #6 - RIGHT
                pie.operator("wm.call_menu", text="Clear Tansformation").name="VIEW3D_MT_object_clear"
                #2 - BOTTOM
                box = pie.split().column()
                row = box.row()
                box.operator("view3d.snap_cursor_to_selected")
                box.operator("wm.call_menu", text="Snap Menu").name="VIEW3D_MT_snap"
                box.separator() 
                box.operator("transform.mirror")
                #8 - TOP
                pie.operator("transform.rotate", text="Rotate") 
                #7 - TOP - LEFT 
                pie.operator("transform.resize", text="Scale")
                #9 - TOP - RIGHT
                pie.operator("wm.call_menu", text="Apply Tansformation").name="VIEW3D_MT_object_apply"
                #1 - BOTTOM - LEFT
                pie.operator("pivotpoint.type", text="Pivot Bounding Box").variable = 'BOUNDING_BOX_CENTER'
                #3 - BOTTOM - RIGHT
                pie.operator("pivotpoint.type", text="Pivot 3D Cursor").variable = 'CURSOR'



# PIE SELECT -------------------------------------------------------------------
class PieSelect(Menu):
    bl_idname = "pie.select"
    bl_label = "Select"

    def draw(self, context):
        layout = self.layout
        pie = layout.menu_pie()


        if(context.mode == 'EDIT_MESH'):

            mesh = context.active_object.data
            scene = context.scene
            #4 - LEFT
            pie.operator("view3d.select_border", text="Border Select")
            #6 - RIGHT
            pie.operator("mesh.select_all", text="De/Select All")
            #2 - BOTTOM
            pie.operator("mesh.select_all", text="Invert Select").action='INVERT'
            #8 - TOP
            pie.operator("mesh.select_mode", text="Edge", icon="EDGESEL").type='EDGE'
            #7 - TOP - LEFT 
            pie.operator("mesh.select_mode", text="Vertex", icon="VERTEXSEL").type='VERT'
            #9 - TOP - RIGHT
            pie.operator("mesh.select_mode", text="Face", icon="FACESEL").type='FACE'
            #1 - BOTTOM - LEFT
            pie.operator("view3d.select_circle", text="Brush Select")
            #3 - BOTTOM - RIGHT
            pie.operator("mesh.select_linked_pick", text="Select Linked")


        else:

            mesh = context.active_object.data
            scene = context.scene              
            #4 - LEFT
            pie.operator("view3d.select_border", text="Border Select")
            #6 - RIGHT
            pie.operator("object.select_all", text="Select All")
            #2 - BOTTOM
            pie.operator("object.select_all", text="Invert Selection").action='INVERT'
            #8 - TOP
            pie = pie.row()
            pie.label('')
            pie = layout.menu_pie()
#            pie.operator("object.move_to_layer")
            #7 - TOP - LEFT 
            pie = pie.row()
            pie.label('')
            pie = layout.menu_pie()\
            #9 - TOP - RIGHT
            pie = pie.row()
            pie.label('')
            pie = layout.menu_pie()
            #1 - BOTTOM - LEFT
            pie.operator("view3d.select_circle", text="Brush Select")
            #3 - BOTTOM - RIGHT
            pie = pie.row()
            pie.label('')
            pie = layout.menu_pie()
$\endgroup$
3
$\begingroup$

It comes down to search order, something else matches before your keymap is found.

If you use the name 'Object Mode' when creating your keymap your items will show up in Preferences->Input in the same place as the default entries and your entry will override blenders select all.

km = wm.keyconfigs.addon.keymaps.new(name='Object Mode')

While it isn't documented, bpy_extras.keyconfig_utils.KM_HIERARCHY[] contains the hierarchy used to display keymaps in Preferences->Input. I haven't verified it's use but this appears to be the order searched to find a match for a keypress. This means that if your entry shows up first in Preferences->Input then it should be the one that responds to the keypress.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.