3
$\begingroup$

I figured out how to disable a keymap by a unique name, but in this case, there are five different keymaps all named wm.call_menu_pie. Is there a way to iterate over it to disable all of them? or if I needed to just disable a specific one, is that possible?

This is the code that works:

bpy.context.window_manager.keyconfigs.active.keymaps['3D View'].keymap_items['wm.call_menu_pie'].active = False
$\endgroup$
4
$\begingroup$

Call pie menu operator

Firstly the name is the id (bl_idname) of the call pie menu operator. The idname of the registered pie menu is passed as name property to the operator.

To call snap pie menu

bpy.ops.wm.call_menu_pie(name="VIEW3D_MT_snap_pie")

Distinguish by the operator's name property

enter image description here

To distinguish between them look at properties passed to the operator.

Test script to make a list of all pie menu short cuts in 3D view (from question). Look for all the keymap items using this operator "wm.call_pie_menu" and populate list with the name of the menu.

import bpy

context = bpy.context

wm = context.window_manager
active = wm.keyconfigs.active
view3d = active.keymaps["3D View"]

# using call menu

pies = [km.properties['name'] for name, km in view3d.keymap_items.items() if name == "wm.call_menu_pie"]

print(pies)

output

['VIEW3D_MT_view_pie', 'VIEW3D_MT_snap_pie', 'VIEW3D_MT_pivot_pie', 'VIEW3D_MT_orientations_pie', 'VIEW3D_MT_shading_pie']

List Comprehension

The list pies is created with list comprehension. Recommend getting head around list comprehension.

To disable all, Note pies is different here, it is being populated with the keymapitems, not the value of the operator name property

enter image description here

pies = [km for name, km in view3d.keymap_items.items() if name == "wm.call_menu_pie"]

for pie in pies:
    pie.active = False

To disable all but snap

enter image description here

for pie in pies:
    pie.active = pie.properties['name'].endswith("snap_pie")

Toggle

enter image description here

for pie in pies:
    pie.active = not pie.active

All call pie menu keymap items in all active keymaps

Create a dictionary of all all the call pie menu operates in each keymap.

all_pies = {
        km.name : [
            kmi for name, kmi in km.keymap_items.items() 
            if name == "wm.call_menu_pie"
            #and kmi.properties['name'].endswith("foo"
        ] 
        for km in active.keymaps
        }

for name, pies in all_pies.items():
    if pies:
        print(name, [pie.properties['name'] for pie in pies])

Result

Grease Pencil Stroke Edit Mode ['GPENCIL_MT_snap_pie', 'VIEW3D_MT_proportional_editing_falloff_pie']
Weight Paint ['VIEW3D_MT_wpaint_vgroup_lock_pie']
Object Mode ['VIEW3D_MT_proportional_editing_falloff_pie']
Curve ['VIEW3D_MT_proportional_editing_falloff_pie']
Sculpt ['VIEW3D_MT_sculpt_mask_edit_pie', 'VIEW3D_MT_sculpt_face_sets_edit_pie']
Mesh ['VIEW3D_MT_proportional_editing_falloff_pie']
Metaball ['VIEW3D_MT_proportional_editing_falloff_pie']
Lattice ['VIEW3D_MT_proportional_editing_falloff_pie']
Particle ['VIEW3D_MT_proportional_editing_falloff_pie']
3D View ['VIEW3D_MT_view_pie', 'VIEW3D_MT_snap_pie', 'VIEW3D_MT_pivot_pie', 'VIEW3D_MT_orientations_pie', 'VIEW3D_MT_shading_pie']
UV Editor ['IMAGE_MT_uvs_snap_pie', 'VIEW3D_MT_proportional_editing_falloff_pie']
Mask Editing ['VIEW3D_MT_proportional_editing_falloff_pie']
Graph Editor ['GRAPH_MT_snap_pie', 'VIEW3D_MT_proportional_editing_falloff_pie', 'GRAPH_MT_pivot_pie']
Image ['IMAGE_MT_pivot_pie']
NLA Editor ['NLA_MT_snap_pie']
Clip ['CLIP_MT_tracking_pie', 'CLIP_MT_solving_pie', 'CLIP_MT_marker_pie', 'CLIP_MT_reconstruction_pie']
Clip Editor ['CLIP_MT_pivot_pie']
$\endgroup$
4
  • $\begingroup$ Wow thanks for the quick response! I don't fully comprehend everything here, but will continue to study and learn. I tried the script and it ran with no errors but didn't quite work. This is what I tried: ``` import bpy context = bpy.context wm = context.window_manager active = wm.keyconfigs.active view3d = active.keymaps["3D View"] pies = [km for name, km in view3d.keymap_items.items() if name == "wm.call_menu_pie"] for pie in pies: pie.active = False ``` $\endgroup$ – Alex Pearce Dec 6 '20 at 7:19
  • $\begingroup$ Have added images re the result of same code. Make sure to mouse over the UI to show updated results. Add print statements to debug, or test in python console. $\endgroup$ – batFINGER Dec 6 '20 at 9:40
  • $\begingroup$ Hmm .. how come I knew this was a batFiNGER answer when I was only 1/5 of the way down it? As usual, much more than a solution :) $\endgroup$ – Robin Betts Dec 6 '20 at 10:16
  • $\begingroup$ @batFINGER you are awesome man. I will try again tomorrow, I am very grateful! $\endgroup$ – Alex Pearce Dec 7 '20 at 5:43

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.