1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
22 "name": "Hotkey: 'Ctrl S'",
23 "description": "Save/Open & File Menus",
24 "blender": (2, 80, 0),
25 "location": "All Editors",
28 "category": "Save Open Pie"
32 from bpy
.types
import (
40 class PIE_MT_SaveOpen(Menu
):
41 bl_idname
= "PIE_MT_saveopen"
42 bl_label
= "Pie Save/Open"
44 def draw(self
, context
):
46 pie
= layout
.menu_pie()
48 pie
.operator("wm.read_homefile", text
="New", icon
='FILE_NEW')
50 pie
.menu("PIE_MT_link", text
="Link Menu", icon
='LINK_BLEND')
52 pie
.menu("PIE_MT_fileio", text
="Import/Export Menu", icon
='IMPORT')
54 pie
.operator("wm.open_mainfile", text
="Open File", icon
='FILE_FOLDER')
56 pie
.operator("wm.save_mainfile", text
="Save", icon
='FILE_TICK')
58 pie
.operator("wm.save_as_mainfile", text
="Save As...", icon
='NONE')
60 pie
.operator("file.save_incremental", text
="Incremental Save", icon
='NONE')
62 pie
.menu("PIE_MT_recover", text
="Recovery Menu", icon
='RECOVER_LAST')
65 class PIE_MT_link(Menu
):
66 bl_idname
= "PIE_MT_link"
69 def draw(self
, context
):
71 pie
= layout
.menu_pie()
72 box
= pie
.split().column()
73 box
.operator("wm.link", text
="Link", icon
='LINK_BLEND')
74 box
.operator("wm.append", text
="Append", icon
='APPEND_BLEND')
76 box
.operator("file.autopack_toggle", text
="Automatically Pack Into .blend")
77 box
.operator("file.pack_all", text
="Pack All Into .blend")
78 box
.operator("file.unpack_all", text
="Unpack All Into Files")
80 box
.operator("file.make_paths_relative", text
="Make All Paths Relative")
81 box
.operator("file.make_paths_absolute", text
="Make All Paths Absolute")
84 class PIE_MT_recover(Menu
):
85 bl_idname
= "PIE_MT_recover"
88 def draw(self
, context
):
90 pie
= layout
.menu_pie()
91 box
= pie
.split().column()
92 box
.operator("wm.recover_auto_save", text
="Recover Auto Save...", icon
='NONE')
93 box
.operator("wm.recover_last_session", text
="Recover Last Session", icon
='RECOVER_LAST')
94 box
.operator("wm.revert_mainfile", text
="Revert", icon
='FILE_REFRESH')
96 box
.operator("file.report_missing_files", text
="Report Missing Files")
97 box
.operator("file.find_missing_files", text
="Find Missing Files")
99 class PIE_MT_fileio(Menu
):
100 bl_idname
= "PIE_MT_fileio"
101 bl_label
= "Import/Export"
103 def draw(self
, context
):
105 pie
= layout
.menu_pie()
106 box
= pie
.split().column()
107 box
.menu("TOPBAR_MT_file_import", icon
='IMPORT')
109 box
.menu("TOPBAR_MT_file_export", icon
='EXPORT')
113 class PIE_OT_FileIncrementalSave(Operator
):
114 bl_idname
= "file.save_incremental"
115 bl_label
= "Save Incremental"
116 bl_description
= "Save First! then Incremental, .blend will get _001 extension"
117 bl_options
= {"REGISTER"}
120 def poll(cls
, context
):
121 return (bpy
.data
.filepath
!= "")
123 def execute(self
, context
):
124 f_path
= bpy
.data
.filepath
125 b_name
= bpy
.path
.basename(f_path
)
127 if b_name
and b_name
.find("_") != -1:
128 # except in cases when there is an underscore in the name like my_file.blend
130 str_nb
= b_name
.rpartition("_")[-1].rpartition(".blend")[0]
131 int_nb
= int(str(str_nb
))
132 new_nb
= str_nb
.replace(str(int_nb
), str(int_nb
+ 1))
133 output
= f_path
.replace(str_nb
, new_nb
)
136 while os
.path
.isfile(output
):
137 str_nb
= b_name
.rpartition("_")[-1].rpartition(".blend")[0]
139 new_nb
= str_nb
.replace(str(int_nb
), str(int_nb
+ i
))
140 output
= f_path
.replace(str_nb
, new_nb
)
142 output
= f_path
.rpartition(".blend")[0] + "_001" + ".blend"
144 # no underscore in the name or saving a nameless (.blend) file
145 output
= f_path
.rpartition(".blend")[0] + "_001" + ".blend"
147 # fix for saving in a directory without privileges
149 bpy
.ops
.wm
.save_as_mainfile(filepath
=output
)
151 self
.report({'WARNING'},
152 "File could not be saved. Check the System Console for errors")
156 {'INFO'}, "File: {0} - Created at: {1}".format(
157 output
[len(bpy
.path
.abspath("//")):],
158 output
[:len(bpy
.path
.abspath("//"))]),
165 PIE_OT_FileIncrementalSave
,
176 bpy
.utils
.register_class(cls
)
178 wm
= bpy
.context
.window_manager
179 if wm
.keyconfigs
.addon
:
181 km
= wm
.keyconfigs
.addon
.keymaps
.new(name
='Window')
182 kmi
= km
.keymap_items
.new('wm.call_menu_pie', 'S', 'PRESS', ctrl
=True)
183 kmi
.properties
.name
= "PIE_MT_saveopen"
184 addon_keymaps
.append((km
, kmi
))
189 bpy
.utils
.unregister_class(cls
)
191 wm
= bpy
.context
.window_manager
192 kc
= wm
.keyconfigs
.addon
194 for km
, kmi
in addon_keymaps
:
195 km
.keymap_items
.remove(kmi
)
196 addon_keymaps
.clear()
199 if __name__
== "__main__":