-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathadd_delete_active_object_property_addon.py
78 lines (60 loc) · 2.18 KB
/
add_delete_active_object_property_addon.py
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
"""
a demo for short key add property and delete property
https://blender.stackexchange.com/questions/201367/how-assign-shortcut-to-custom-function
"""
import bpy
bl_info = {
"name": "TestAddAndDeleteProperty",
"author": "Liyou Wang",
"version": (1, 0),
"blender": (2, 92, 0),
"location": "View3D > Select > AddProperty",
"description": "TestAddAndDeleteProperty",
"warning": "",
"wiki_url": "",
"category": "3D View",
}
class AddProperty(bpy.types.Operator):
"""add acticve object property"""
bl_idname = "object.add_property"
bl_label = "add_property"
bl_description = "add_property"
bl_space_type = "VIEW_3D"
bl_region_type = 'UI'
@classmethod
def poll(cls, context):
return context.space_data.type == 'VIEW_3D'
def invoke(self, context, event):
bpy.context.active_object["binary_coordinate"] = {"faceid":1, "w1":0.5, "w2":0.5}
return {'PASS_THROUGH'}
class DeleteProperty(bpy.types.Operator):
"""delete acticve object property"""
bl_idname = "object.delete_property"
bl_label = "delete_property"
bl_description = "delete_property"
bl_space_type = "VIEW_3D"
bl_region_type = 'UI'
@classmethod
def poll(cls, context):
return context.space_data.type == 'VIEW_3D'
def invoke(self, context, event):
del bpy.context.active_object["binary_coordinate"]
return {'PASS_THROUGH'}
def menu_func(self, context): ## creating the menu item
self.layout.operator(AddProperty.bl_idname, icon='MESH_CUBE')
self.layout.operator(DeleteProperty.bl_idname, icon='MESH_CUBE')
classess = [AddProperty, DeleteProperty]
def register():
for cls in classess:
bpy.utils.register_class(cls)
bpy.types.VIEW3D_MT_select_object.append(menu_func)
# wm = bpy.context.window_manager
# kc = wm.keyconfigs['Blender User']
# km = kc.keymaps['3D View']
# kmi = km.keymap_items.new(ViewOperatorRayCast.bl_idname, 'MOUSEMOVE', 'ANY', ctrl=True)
def unregister():
for cls in classess:
bpy.utils.unregister_class(cls)
bpy.types.VIEW3D_MT_select_object.remove(menu_func)
if __name__ == "__main__":
register()