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
|
# SPDX-License-Identifier: GPL-2.0-or-later
"""
Save & Reload File
When working with linked libraries, very often you need to save and load
again to see the changes.
This does it in one go, without asking, so be careful :)
Usage: Hit Ctrl + Shift + W or find it at the bottom of the File menu.
"""
import bpy
KEYMAPS = list()
class AMTH_WM_OT_save_reload(bpy.types.Operator):
"""Save and Reload the current blend file"""
bl_idname = "wm.save_reload"
bl_label = "Save & Reload"
def save_reload(self, context, path):
if not path:
bpy.ops.wm.save_as_mainfile("INVOKE_AREA")
return
bpy.ops.wm.save_mainfile()
self.report({"INFO"}, "Saved & Reloaded")
bpy.ops.wm.open_mainfile("EXEC_DEFAULT", filepath=path)
def execute(self, context):
path = bpy.data.filepath
self.save_reload(context, path)
return {"FINISHED"}
def button_save_reload(self, context):
get_addon = "amaranth" in context.preferences.addons.keys()
if not get_addon:
return
if context.preferences.addons["amaranth"].preferences.use_file_save_reload:
self.layout.separator()
self.layout.operator(
AMTH_WM_OT_save_reload.bl_idname,
text="Save & Reload",
icon="FILE_REFRESH")
def register():
bpy.utils.register_class(AMTH_WM_OT_save_reload)
bpy.types.TOPBAR_MT_file.append(button_save_reload)
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
km = kc.keymaps.new(name="Window")
kmi = km.keymap_items.new("wm.save_reload", "W", "PRESS",
shift=True, ctrl=True)
KEYMAPS.append((km, kmi))
def unregister():
bpy.utils.unregister_class(AMTH_WM_OT_save_reload)
bpy.types.TOPBAR_MT_file.remove(button_save_reload)
for km, kmi in KEYMAPS:
km.keymap_items.remove(kmi)
KEYMAPS.clear()
|