Incremental saves

Share your scripts with other members
Chman
Posts: 213
Joined: Wed Jun 20, 2007 12:34 pm
Contact:

Incremental saves

Postby Chman » Tue Aug 07, 2007 3:06 pm

Hi,

I made a batch script for my own purpose some months ago, maybe it'll be useful to others... It's an incremental save function (those coming from 3dsmax will understand its power).

Description : it appends a sequence number to the project file name, or increments the sequence number if the name already has one, and then saves the file to that name. Useful to avoid file corruption or doing fast Save As and keeping multiple versions of the scene efficiently.

Here's the script :

Code: Select all

# Name : Incremental save
# Description: Emulates the 3dsmax "Save +" feature : it appends a sequence
#   number to the project file name, or increments the sequence number if
#   the name already has one, and then saves the file to that name.  Useful to
#   avoid file corruption or doing fast Save As.
# Icon : incremental_save.png
#
# Author    : Thomas Hourdel
# Date       : Tuesday, 04 June 2007
# Version   : 1.0
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

import re

def main():

   # Get some needed strings
   root_path = scene.getRootPath()
   file_name = scene.getFileName()
   base_file_name = file_name[0:file_name.find(.flw)]
   
   # Try to detect existing counter using regular expressions
   digits = ""
   had_digits = False
   exp = re.compile("[0-9]*$").search(base_file_name)
   if exp:
      digits = exp.group()
      had_digits = True
   else:
      digits = "00"
      
   digits_nbr = len(digits)
   
   if had_digits:
      base_file_name = base_file_name[0:len(base_file_name)-digits_nbr]

   if (digits_nbr < 1):
      digits_nbr = 2
   
   digits = int(digits)
   digits += 1
   digits = str(digits).zfill(digits_nbr)
   
   # Save file
   scene.save(root_path + "/" + base_file_name + digits + ".flw")
   
   # Return 0 on success.
   return(0)

if __name__ == "RealFlow":
   main()

The icon is attached to this post.

I use it all the time, so I'm pretty sure it's perfectly safe.

Tom

Attached files


shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Incremental saves

Postby shaun_michael » Tue Aug 07, 2007 3:35 pm

That looks very useful Tom, thank you for sharing :)

Shaun


Return to “User Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest