Problem with Hotkey

Hi everyone!
I’m new in this forum, I’m new in Blender Scripting…
So I saw tutorials for begginers, and i’m having a problem with “Custom Menu” Tutorial (from blender cookie).
I wanted to add a Hotkey for my Custom Menu, but the console aways says:

" search for unknow operator ‘VIEW3D_OT_custom_menu’, ‘VIEW3D_OT_custom_menu’ "

I have tried many things and nothing works. But when I call the menu without hotkey it’s works!
Please, can someone help me? ><

I’m using Blender 2.73

Here is the code

bl_info = {
        "name": "My Custom Menu",
        "category": "3D View",
        "author": "Kah"
         }


import bpy

class removeMaterial(bpy.types.Operator):
    bl_label = "Remove Unused Materials"
    bl_idname = "view3d.remove_unused_materials"
    
    def execute(self, context):
        mat = bpy.data.materials
        for m in mat:
            if m.users == 0:
                mat.remove(m)
        return {"FINISHED"}
 
 
 
    
# Creates a menu for global 3D View
class customMenu(bpy.types.Menu):
    bl_label = "Custom Menu"
    bl_idname = "view3D.custom_menu"
    
    
    #Set the menu operators and draw function
    def draw(self, context):
        layout = self.layout
        layout.operator("mesh.primitive_cube_add", icon="MESH_CUBE")
        layout.operator("view3d.remove_unused_materials", "Remove Unused Materials")


addon_keymaps = [] #store keymaps here to acess after registration

#Make Blender know it exists for addons
def register():
    bpy.utils.register_class(removeMaterial)
    bpy.utils.register_class(customMenu)
    
#bpy.ops.wm.call_menu(name=customMenu.bl_idname)
#Handle the keymap
    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    
    if kc:
        km = wm.keyconfigs.addon.keymaps.new(name="Window", space_type="EMPTY", region_type='WINDOW')
        kmi = km.keymap_items.new(customMenu.bl_idname, type="Q", value="PRESS", shift=True)
        addon_keymaps.append((km,kmi))

def unregister():
    
    #handle the keymaps
    
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    #clear the list
    addon_keymaps.clear()
    
    bpy.utils.unregister_class(removeMaterial)
    bpy.utils.unregister_class(customMenu)
    
    
    

if __name__=="__main__":
    register()

Thank you :slight_smile:

Same problem here. The hotkey assigned to my hotkey used to work fine on version 2.69, but now on 2.74 it gives me the “menu [name of the menu] not found”. The problem seems to be with the assigning, since the script itself works just fine when called from the spacebar search field.

Could anyone help us, please?

Hello, Kaedy. I found a solution that worked for me. It seems the tutorial you followed is now outdated due to some alterations in new versions of Blender. Try to do as explained in the image. If this works for you, please don’t forget to mark your post as [SOLVED].