1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
"""
Custom item in the right click menu
+++++++++++++++++++++++++++++++++++
This example enables you to insert your own menu entry into the common
right click menu that you get while hovering over a value field,
color, string, etc.
To make the example work, you have to first select an object
then right click on an user interface element (maybe a color in the
material properties) and choose "Execute custom action".
Executing the operator will then dump all values directly to a
console, so make sure to open a terminal by clicking on
"Help >> Toggle System Console" or execute Blender directly
from a terminal on your system of choice)
"""
import bpy
from bpy.types import Header, Menu, Panel
def dump(obj, text):
print('-'*40, text, '-'*40)
for attr in dir(obj):
if hasattr( obj, attr ):
print( "obj.%s = %s" % (attr, getattr(obj, attr)))
class TEST_OT_Rmb(bpy.types.Operator):
"""Right click entry test"""
bl_idname = "object.rmb_test_op"
bl_label = "Execute custom action"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
if hasattr(context, 'button_pointer'):
btn = context.button_pointer
dump(btn, 'button_pointer')
if hasattr(context, 'button_prop'):
prop = context.button_prop
dump(prop, 'button_prop')
if hasattr(context, 'button_operator'):
op = context.button_operator
dump(op, 'button_operator')
return {'FINISHED'}
# This class has to be exactly named like that to insert an entry in the right click menu
class WM_MT_button_context(Menu):
bl_label = "Add Viddyoze Tag"
def draw(self, context):
pass
def menu_func(self, context):
layout = self.layout
layout.separator()
layout.operator("object.rmb_test_op")
classes = (
TEST_OT_Rmb,
WM_MT_button_context,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.WM_MT_button_context.append(menu_func)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
bpy.types.WM_MT_button_context.remove(menu_func)
if __name__ == "__main__":
register()
|