Modify RMB context sensitive menus

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Posts: 0
Joined: Wed Mar 20, 2013 1:35 am

Modify RMB context sensitive menus

Post by orimouse »

I have 2 little questions about RMB menus :oops:

When I create a panel with properties, i can add -to a float property for exemple- a keyframe or driver, or add to keying set etc... with RMB menu.

But I don't want the user to have access to this.
So the first question is : How can I disable those options ?

I mean, like in Vertex Groups list, the RMB menu is shorter, and some options are unavailable.

And, the contrary : how can I add a custom option to RMB menu ?

I couldn't find anything consistent to guide me :cry:, so if anyone could help me, I'll be very grateful. :)

Posts: 0
Joined: Wed Mar 20, 2013 1:35 am

Post by orimouse »

Here's a simple script to explain the problem :

Code: Select all

import bpy
from bpy.props import *
#    Store properties in the active object
def initObjectProperties(obj):

    bpy.types.Object.TestFloat = FloatProperty(
        name = "Float", 
        description = "Enter a float",
        default = 5.25,
        min = -100,
        max = 100)
#    Menu in UI region
class UIPanel(bpy.types.Panel):
    bl_label = "Property panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOL_PROPS"
    def draw(self, context):
        layout = self.layout
        obj = bpy.context.object

        layout.prop(obj, 'TestFloat')

#    Registration
So in the tool properties I have the float value. When I RMB click on it, the menu shows some options, such as "Add driver", "Insert Keyframe"...

I've found some threads on the web such as ... in-a-scene
But it's not really clear for me...

Is it possible to modify RMB context sensitive menus in a simple script ?

I've looked a bit in included addons that have shorter menus on their properties, and nothing in the code explicitely says how to modify the RMB menus...

The only difference I've found is that the class drawing the menu and where the properties are defined derivates from bpy.types.Operator and there's absolutely no class from bpy.types.Panel...

I'd be thankful if someone could give me a hint, where to look in the API for example...

Thank you !

Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

those context menus are built-in and apperently not accessible by python. You could, however, replace them entirely by binding a custom menu to the right mouse button. I don't recommend it though
I'm sitting, waiting, wishing, building Blender in superstition...

Posts: 0
Joined: Wed Mar 20, 2013 1:35 am

Post by orimouse »

That's what I feared, but at least I won't spend much time to try to modify it.
Thank you for your answer :)

Post Reply