-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview3d_pt_presets.py
66 lines (45 loc) · 1.81 KB
/
view3d_pt_presets.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
import bpy
class ViewportPresets(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Viewport presets panel"
bl_idname = "VIEW3D_PT_presets"
bl_space_type = 'VIEW_3D'
bl_region_type = 'HEADER'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
prefs = context.preferences.addons[__package__].preferences
layout.label(text="Presets")
row = layout.row()
col = row.column(align=True)
i = 0
for preset in prefs.presets:
op = col.operator('view3d.applypreset', text=preset.name, depress = (prefs.selected_index == i) )
op.index = i
params = op.preset.__annotations__.keys()
for param in params:
setattr(op.preset, param, getattr(preset, param))
i = i + 1
row.operator("view3d.savepreset", text="", icon='ADD', emboss=False)
if (prefs.selected_index >= 0):
layout.prop(prefs.presets[prefs.selected_index], "name", text="Rename")
row = layout.row()
row.operator('view3d.savepreset', text='Update').index = prefs.selected_index
row.operator('view3d.deletepreset', text='Delete').index = prefs.selected_index
row=layout.row()
row.operator("wm.save_userpref")
def view3d_presets_draw(self, context):
layout = self.layout
self.layout.popover(
panel="VIEW3D_PT_presets",
text="Presets",
)
def register():
bpy.utils.register_class(ViewportPresets)
bpy.types.VIEW3D_HT_header.append(view3d_presets_draw)
def unregister():
bpy.utils.unregister_class(ViewportPresets)
bpy.types.VIEW3D_HT_header.remove(view3d_presets_draw)
if __name__ == "__main__":
register()