Changing the right click behavior...

Hello BA!

I’m mainly an C4D user and I’m slowly trying to adapt Blender to work kinda like C4D… Please don’t judge me… :slight_smile:

So here’s my question:
Since I like to select stuff with left click (by the way I already changed that in Blender), I would like to know if it’s possible to have the right click to show different menus when in different modeling modes?
E.g. when I’m in faces mode, my right click should show the mesh option for the faces and so on…
I think it’s a good way of work… :wink:

See:

Thanks.

Save the following code as mesh_context_menu.py and put it into your addons directory, or use Install From File… so Blender puts it there for you. Activate the add-on. Then in input editor (3D View -> Mesh) assign mouse right click to call mesh.addon_call_context_menu.

This should show either a component menu or a menu with sub-menus if more than one component selection mode is active.


# Save as mesh_context_menu.py and put it into addons directory
# (or use Blender's Install From File... function).

bl_info = {
    "name": "Mesh Context Menu",
    "author": "Stanislav Blinov",
    "version": (1, 0, 0),
    "blender": (2, 74, 0),
    "description": "Context-sensitive mesh menu",
    "category": "Mesh",
}

import bpy

class MESH_MT_CombinedMenu(bpy.types.Menu):
    bl_idname = "mesh.addon_combined_component_menu"
    bl_label = "Components"

    @classmethod
    def poll(cls, context):
        return context.mode == 'EDIT_MESH'

    def draw(self, context):
        layout = self.layout
        
        mode = context.tool_settings.mesh_select_mode
        if mode[0]: layout.menu("VIEW3D_MT_edit_mesh_vertices")
        if mode[1]: layout.menu("VIEW3D_MT_edit_mesh_edges")
        if mode[2]: layout.menu("VIEW3D_MT_edit_mesh_faces")

class MESH_OT_CallContextMenu(bpy.types.Operator):
    bl_idname = "mesh.addon_call_context_menu"
    bl_label = "Context Menu"
    
    @classmethod
    def poll(cls, context):
        return context.mode == 'EDIT_MESH'

    def execute(self, context):
        mode = context.tool_settings.mesh_select_mode
        num = sum(int(m) for m in mode)
        if num == 1:
            if mode[0]: return bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_vertices")
            if mode[1]: return bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_edges")
            if mode[2]: return bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_faces")
        else:
            return bpy.ops.wm.call_menu(name=MESH_MT_CombinedMenu.bl_idname)
        
classes = [ MESH_MT_CombinedMenu,
            MESH_OT_CallContextMenu ]
    
def register():
    for c in classes:
        bpy.utils.register_class(c)
    
def unregister():
    for c in classes:
        bpy.utils.unregister_class(c)
    
if __name__ == "__main__":
    register()

Wow…
I followed your instructions and tested your code. I can only say wow, it’s working perfectly.
Thank you so much.
I’m so happy… :slight_smile:
Thank you…
Thank you…
Thank you…
I can’t thank you enough for what you did… :slight_smile:

Good luck, and God bless you.

By the way, if you are willing to develop this addon even further, please let me know. I have some ideas, and I can post here if you allow me. :slight_smile:
Cheers.

hi, I like this.
I’ve just mapped to Right Mouse Double click so it doe not interfere with selection.
It’s not hard to add a keymap to this if you like.
imo, I’m tempted to add this to the spacebar menu addon as an extra keymap.

You are welcome, Regnas :slight_smile:

Don’t know if there’s anything further to do about it, it’s just built-in menus. Though I see Meta-Androcto already thought of something. Myself, I won’t get much use out of it: mesh selection in Blender is mixed, so there’s nothing preventing you from using, say, edge or face operations while you’re in vertex selection mode, which such menu won’t allow. I just quickly made it to help you out in mending Blender against it’s nature :wink:

Meta, double click? Does it really not interfere with selection? Or does it still select on first click, call menu on second one? I’m using a rather customized input layout, and have double click mapped to Select Linked, but it’s still two distinct actions, two "undo"s :
Also, did you look at rRMB I linked earlier? It seems to have way more goodies in it.

hi Stan,
yes it’s two actions with double click, one to select, one to call menu.
struggling with the keymap though…
no wonder, I was editing the wrong file…

here we go, mapped to right double click


# Save as mesh_context_menu.py and put it into addons directory
# (or use Blender's Install From File... function).


bl_info = {
    "name": "Mesh Context Menu",
    "author": "Stanislav Blinov",
    "version": (1, 0, 0),
    "blender": (2, 74, 0),
    "description": "Context-sensitive mesh menu",
    "category": "Mesh",
}


import bpy
from bpy_extras import view3d_utils


class MESH_MT_CombinedMenu(bpy.types.Menu):
    bl_idname = "mesh.addon_combined_component_menu"
    bl_label = "Components"


    @classmethod
    def poll(cls, context):
        return context.mode == 'EDIT_MESH'


    def draw(self, context):
        layout = self.layout
        
        mode = context.tool_settings.mesh_select_mode
        if mode[0]: layout.menu("VIEW3D_MT_edit_mesh_vertices")
        if mode[1]: layout.menu("VIEW3D_MT_edit_mesh_edges")
        if mode[2]: layout.menu("VIEW3D_MT_edit_mesh_faces")


class MESH_OT_CallContextMenu(bpy.types.Operator):
    bl_idname = "mesh.addon_call_context_menu"
    bl_label = "Context Menu"
    
    @classmethod
    def poll(cls, context):
        return context.mode == 'EDIT_MESH'


    def execute(self, context):
        mode = context.tool_settings.mesh_select_mode
        num = sum(int(m) for m in mode)
        if num == 1:
            if mode[0]: return bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_vertices")
            if mode[1]: return bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_edges")
            if mode[2]: return bpy.ops.wm.call_menu(name="VIEW3D_MT_edit_mesh_faces")
        else:
            return bpy.ops.wm.call_menu(name=MESH_MT_CombinedMenu.bl_idname)
        
classes = [ MESH_MT_CombinedMenu,
            MESH_OT_CallContextMenu ]


    
def register():
    # add operator
    for c in classes:
        bpy.utils.register_class(c)


    # add keymap entry
    
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name='3D View', space_type='VIEW_3D')
    kmi = km.keymap_items.new('mesh.addon_call_context_menu', 'RIGHTMOUSE', 'DOUBLE_CLICK')




def unregister():
    # remove keymap entry
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()
    
    # remove operator and preferences
    for c in reversed(classes):
        bpy.utils.unregister_class(c)




if __name__ == "__main__":
    register()




Hello Stan.

My ideas are quite simple actually.
I just want the same functionality in object mode (the object menu in right click), and append some sub menus in all modes if possible.

See the following example:


Is this possible?
By the way, a few more sub menus are welcome as well… :slight_smile:

Now, the addon you linked is ok, but I don’t like his “hardcoded ?” nature… And the menus that I want (the mesh options etc), are in sub menus, which is not the place I want it to be etc…

Cheers.
Thanks…

hi, try the dynamic spacebar addon, it has many menu modifications. including the menu’s you ask for now.
You could change it’s key map to right click or double right click easily or use it as a base to design your own custom menu.

Hi.
Sorry, but where can I find this add-on?
Thanks.