0
$\begingroup$

Blender Version: 3.6.5 from Steam i'm currently working on an add-on for a pie menu, currently none of the methods i could find online nor my own mixes of those seems to work

  • keymaps are not being added
  • there is no error in the console
  • refreshing addons does nothing to the keymaps

this is a variation of the same method i was using in a previous version but due to a blender bug a lot of duplicates were generated and i needed to reset keymaps preference, now it has stopped working completely

The Code here is almost a full copy of an answer on another post, i tried methods from blender's built-in addons none of those work either

Note: sometimes(rarely) it does add a keymap but it's gone after restart, and trying to to save preferences stops the addon from being enabled

The code works, the keybind doesn't: YT Video

Full Code Here in case it's coming from something unrelated to the keymaps code: Github

addon_keymaps = []

def register():
    for AlxQCls in AlxClassQueue:
        bpy.utils.register_class(AlxQCls)

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon

    km = kc.keymaps.new(name='3D View')
    kmi = km.keymap_items.new(idname="wm.call_menu_pie", type="A", value="CLICK", ctrl=True, shift=False, alt=True, head=True)
    kmi.properties.name = Alx_MT_AlexandriaToolPie.bl_idname

    addon_keymaps.append((km,kmi))

    print("AlxRegister Called")
    print("ALX_LIBRARY_LOADED")
    print(AlxClassQueue)
$\endgroup$
6
  • $\begingroup$ I think value should be 'PRESS' with keyboard keys, not sure if that might be the cause of the problem though. $\endgroup$ Oct 31, 2023 at 14:20
  • $\begingroup$ i originally thought that too but it doesn't work regardless of the value type it was originally "PRESS" and that too fails, the thing that i'm currently looking into is that the issue might lie in how pie menu keybinds are assigned, as other non pie menu keys seem to work more consistently, either wm.call_menu_pie is the issue or property.name as when those are not present an empty keybind is added succesfully $\endgroup$
    – ValyArhal
    Oct 31, 2023 at 14:41
  • $\begingroup$ I think it might be elsewhere in the code then. $\endgroup$ Oct 31, 2023 at 14:57
  • $\begingroup$ the pie menu can actually be called and works correctly, it was originally a panel that got adapted to a pie menu, things like custom buttons and the search menu allow it to open with no issues, but any keybind added in the addon works even for pie menus but adding wm.call_menu_pie with a property.name adds no keymap even for existing pie menus, i tried "hijacking" both bagapie and machin3tools bl_idname and still doesn't work $\endgroup$
    – ValyArhal
    Oct 31, 2023 at 15:07
  • $\begingroup$ The code doesn't run. You put everything in needlessly many functions and call them before they are defined and also try to use variables that are not yet defined. The order in which you write code matters. Why not just add all the classes to a list and register them in register function in a loop? I think you should put the handler in register/unregister functions as well. I think it's also not that usual to have match-case statement for only 2 cases based on boolean value - that should just be an if statement. $\endgroup$ Nov 1, 2023 at 0:07

1 Answer 1

0
$\begingroup$

tldr properties.name should respect alx_name_here for ui and alx.name_here for operators

The issue with this was the documentation all along, nowhere there is the mention that properties.name when assigning a menu to wm.call_pie_menu the item bl_idname need to follow that standard, which in this case the . present in the panel was not reported with an error

the previously mentioned reason was a missguiding due to internal blender naming conventions have class name identical to bl_idnames

12/02/2024

semi working function for keymaps with which i resolved the issue:

def AlxKeymapRegister(KeymapCallType="", SpaceType="EMPTY", RegionType="WINDOW", ItemidName="", Key="", KeyModifier="", UseShift=False, UseCtrl=False, UseAlt=False, TriggerType="PRESS"):
    """
    Keymap Call Type: [OPERATOR, MENU, PANEL, PIE]
    Region Type: [WINDOW]
    """
    if (ItemidName != ""):
        WindowManager = bpy.context.window_manager
        KeyConfigs = WindowManager.keyconfigs.addon

        if KeyConfigs:

            CallType = ""
            if (KeymapCallType == "OPERATOR"):
                CallType = ItemidName
            if (KeymapCallType == "MENU"):
                CallType = "wm.call_menu"
            if (KeymapCallType == "PANEL"):
                CallType = "wm.call_panel"
            if (KeymapCallType == "PIE"):
                CallType = "wm.call_menu_pie"

            KeymapName = ""
            if (RegionType == "WINDOW") and (SpaceType != "VIEW_3D"):
                KeymapName = "Window"
                SpaceType = "EMPTY"
            if (SpaceType == "VIEW_3D"):
                KeymapName = "3D View"
            
            if (KeyModifier == ""):
                KeyModifier = "NONE"

            if (CallType != "") and (SpaceType != ""):
                Keymap = KeyConfigs.keymaps.new(name=KeymapName, space_type=SpaceType, region_type=RegionType)
                KeymapItem = Keymap.keymap_items.new(CallType, type=Key, key_modifier=KeyModifier, shift=UseShift, ctrl=UseCtrl, alt=UseAlt, value=TriggerType, head=True)
                if (KeymapCallType in ["PANEL", "PIE"]):
                    KeymapItem.properties.name = ItemidName
                AlxAddonKeymaps.append((Keymap, KeymapItem))
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .