[Bf-extensions-cvs] [d181537] master: fix for underscore in incremental file save, thanks lijenstina
meta-androcto
noreply at git.blender.org
Mon Jun 20 09:10:54 CEST 2016
Commit: d18153781fcb114d92e25aa92af2f23c7d8441a7
Author: meta-androcto
Date: Mon Jun 20 17:10:34 2016 +1000
Branches: master
https://developer.blender.org/rBACd18153781fcb114d92e25aa92af2f23c7d8441a7
fix for underscore in incremental file save, thanks lijenstina
===================================================================
M ui_pie_menus/pie_save_open_menu/__init__.py
===================================================================
diff --git a/ui_pie_menus/pie_save_open_menu/__init__.py b/ui_pie_menus/pie_save_open_menu/__init__.py
index 157b056..de2843f 100644
--- a/ui_pie_menus/pie_save_open_menu/__init__.py
+++ b/ui_pie_menus/pie_save_open_menu/__init__.py
@@ -17,6 +17,7 @@ from bpy.types import Menu, Header
from bpy.props import IntProperty, FloatProperty, BoolProperty
from mathutils import *
import math
+import os
# Pie Save/Open
class PieSaveOpen(Menu):
@@ -83,21 +84,25 @@ class FileIncrementalSave(bpy.types.Operator):
def execute(self, context):
f_path = bpy.data.filepath
if f_path.find("_") != -1:
- str_nb = f_path.rpartition("_")[-1].rpartition(".blend")[0]
- int_nb = int(str_nb)
- new_nb = str_nb.replace(str(int_nb), str(int_nb + 1))
- output = f_path.replace(str_nb, new_nb)
-
- i = 1
- while os.path.isfile(output):
+ # fix for cases when there is an underscore in the name like my_file.blend
+ try:
str_nb = f_path.rpartition("_")[-1].rpartition(".blend")[0]
- i += 1
- new_nb = str_nb.replace(str(int_nb), str(int_nb + i))
+ int_nb = int(str(str_nb))
+ new_nb = str_nb.replace(str(int_nb), str(int_nb + 1))
output = f_path.replace(str_nb, new_nb)
+
+ i = 1
+ while os.path.isfile(output):
+ str_nb = f_path.rpartition("_")[-1].rpartition(".blend")[0]
+ i += 1
+ new_nb = str_nb.replace(str(int_nb), str(int_nb + i))
+ output = f_path.replace(str_nb, new_nb)
+ except ValueError:
+ output = f_path.rpartition(".blend")[0] + "_001" + ".blend"
else:
output = f_path.rpartition(".blend")[0] + "_001" + ".blend"
-
bpy.ops.wm.save_as_mainfile(filepath=output)
+
self.report({'INFO'}, "File: {0} - Created at: {1}".format(output[len(bpy.path.abspath("//")):], output[:len(bpy.path.abspath("//"))]))
return {'FINISHED'}
More information about the Bf-extensions-cvs
mailing list