0
$\begingroup$

// Edit 2/20/2022: First of all I just want to say that I still havent found a solution as of now! So more answers are needed.

So as by @pyCod3R 's example. If I were to replace the line bl_idname = "object.simple_operator" with bl_idname = "fast_pbr.simple_operator". Again the issue appears in his example as well.

As my addon is somewhat large (Close to 20 operators total), I want them all to fit under the same roof, so if possible I would rather like to avoid registering them under simply "object".

So I guess the question has now changed to:

How do I enable the "Assign shortcut" button in RMB for operators registered with a custom namespace of my own? Do I need to "register" the namespace itself somewhere?

// End of edit

So Ive noticed that the popup menu which appears when right clicking any of the operators registered to the UI in my addon is missing the "Assign shortcut" button. I can still go into the keymaps preferences and add an entry there manually. I can also just add a hotkey using bpy using something like:

keyConfig.keymaps["Window"].keymap_items.new("fast_pbr.fast_upbge_pie", type="NONE", value="PRESS")

Where setting the type (which determines which key is assigned to the keymap entry we are adding) to NONE one would imagine the "Assign shortcut" thing to appear in the RMB menu, of which it does not (setting it to "NONE" results in no change to the RMB menu, setting it to anything but "NONE" results in "Change shortcut" to appear in the menu, but then we are assigning a shortcut, which in my case is undesired as I just want to make it easy for the users to assign a shortcut without actually holding any keys hostage by default).

Does anyone know how to get this "Assign Shortcut" button to appear for operators that I register myself as a part of my addon?

enter image description here enter image description here

Thanks for reading 💝

$\endgroup$
3
  • $\begingroup$ @MartyFouts are you sure this will achieve what the question asks ? $\endgroup$
    – Gorgious
    Jan 13, 2022 at 9:21
  • $\begingroup$ @MartyFouts can you be more specific here? Where does that Text variable live? Is it a parameter or a class member? Also like Gorgious said, are you sure you read my question correctly (Im not looing to override Add to quick favorites, I want to keep that there as well ofc. Assign shortcut offers different functionality) $\endgroup$ Jan 13, 2022 at 10:52
  • $\begingroup$ Sorry, I did read the question wrong. $\endgroup$ Jan 13, 2022 at 14:48

1 Answer 1

1
$\begingroup$

Works out of the box and there is nothing to do. Example of a built-in operator vs. custom operator, it's the same menu for both.

enter image description here

import bpy

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    
    def execute(self, context):
        return {'FINISHED'}

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout
        row = layout.row()
        row.operator("mesh.primitive_cube_add")
        row.operator(SimpleOperator.bl_idname)

def register():
    bpy.utils.register_class(SimpleOperator)
    bpy.utils.register_class(HelloWorldPanel)

def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    bpy.utils.unregister_class(HelloWorldPanel)

if __name__ == "__main__":
    register()
$\endgroup$
1
  • $\begingroup$ Hi and sorry for the somewhat delayed reply! It appears that if I replace bl_idname = "object.simple_operator" with bl_idname = "fast_pbr.simple_operator" in your example, the assign shortcut menu disappears! To keep my stuff organized I will want to register my things under my own name space (fast_pbr in this case). Any thoughts? (Im guessing this is the issue Im having with my addon) $\endgroup$ Jan 23, 2022 at 15:24

You must log in to answer this question.

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