SUMMARY
When setting up projects within Katana, saving while progressing is essential to avoid loss of data and time. Katana has inbuilt autosave functionality, which saves a backup crash file after a certain amount of time or actions.
For more information on Crash Saves, please refer to the Katana User Guide: Autosaves
This article demonstrates how to set up an autosave script, which can be used to save to a custom location with a custom naming convention rather than to Katana’s temporary directory with an automatically generated file name, which is the default behaviour of the autosave functionality.
MORE INFORMATION
Katana saves its project files through the KatanaFile module within the Katana Python API.
Calling KatanaFile.Save(path/to/location/file.katana) will save the current Katana project to the chosen location using the chosen file name.
Calling KatanaFile.CrashSave() will save a crash file of the current Katana project with an auto-generated name, to a temporary directory from where it can be restored using the Katana Crash File Selector.
For more information on restoring autosave files, please see the following article: Q100450: How to Find and Recover an Autosaved File After a Crash
Using the functions described above, you can create a Python script which automatically saves the Katana project at specified time intervals.
For more information on the KatanaFile module, please refer to the Katana Developer Guide: Working with Projects
EXAMPLE SCRIPT
Attached to this article is a Python example, which can be downloaded and modified for your needs.
Download the example and move the file to your .katana\UIPlugins folder.
For example:
Windows: C:\Users\USERNAME\.katana\UIPlugins\autosaveProject.py
Linux: /mnt/nethome/users/USERNAME/.katana/UIPlugins/autosaveProject.py
When the file is added to the UIPlugins folder, Katana will load and execute the file on startup.
USING THE SCRIPT
The script has 3 options you can choose from via setting the saveOption variable. It additionally has an option for the time between saves, for the example script, it is currently set at 60000 milliseconds (60 seconds).
Please review the options below:
Option 0: Force autosave crash save
This option allows you to force a new CrashSave through Python.
Although Katana has an inbuilt crash autosave, this function can be useful for setting up before running functions with Python.
Option 1: Save over current project file
Using this option will overwrite the current project with a new save.
Katana will only save the file when the project has been modified.
Option 2: Save the file to a specified location
This option works the same as option 1 but allows you to choose a directory location and name.
You will need to alter the script to add your desired save location.
Additionally, you will need to create a tool to check for autosave files on startup.
from Katana import QtCore, NodegraphAPI, KatanaFile
import os
# VARIABLES
# Set your save option
saveOption = 2
# Set delay interval for autosaves
# function argument is the interval in milliseconds (60 seconds in this example)
autosaveDelay = 60000
def saveAndSubmit():
''' Autosaves project with option specified by user '''
# Get path variables
projectPath = NodegraphAPI.NodegraphGlobals.GetProjectFile()
projectFile = os.path.basename(projectPath)
projectDir = os.path.dirname(projectPath)
# OPTION 0
# Q100450: Locating a crash autosave file - https://support.foundry.com/hc/en-us/articles/360000024960
# Save a crash file (standard autosave):
if saveOption == 0:
KatanaFile.CrashSave(True)
# Check if file has been saved atleast once.
if projectPath != '':
# Check if file has been modified since last save
if KatanaFile.IsFileDirty():
# OPTION 1
# to save file at the current location use:
if saveOption == 1:
KatanaFile.Save(projectPath)
print ("File autosaved to: " + projectPath)
# OPTION 2
# to save at a specified location use:
if saveOption == 2:
customNameFile = 1 # If you want to use a different project name change the customNameFile = 0
customprojectFile = projectFile #Overwrites the active save with any changes (only happens if customNameFile is not 0
# Custom folder directory for Option 2
customFolderDirectory = '/home/userName/Downloads/customFolder/'
if customNameFile == 0:
customprojectFile = 'CustomFileName' # If customNameFile is 0 then you can change CustomFileName for whatever name you want the file to be save as
KatanaFile.Save(customFolderDirectory + customprojectFile)
print ("File autosaved to: " + customFolderDirectory + customprojectFile)
timer = QtCore.QTimer()
timer.timeout.connect(saveAndSubmit)
timer.start(autosaveDelay)
SCRIPT EXPLANATION
The script is using a QtCore.QTimer()
call to provide a timer loop. Using the QTimer allows for a background function to wait for a certain amount of time before executing the script’s function.
Each time the specified amount of time has elapsed (determined by the autosaveDelay variable), the timer runs the saveAndSubmit()
function.
Within the saveAndSubmit()
function definition, there are the 3 options that are switchable with the saveOption variable.
Depending on the option chosen, the script will either save as a crashSave, save over the current Katana file, or save in a new location.
Option 1 and 2 first check the result of another function named KatanaFile.IsFileDirty()
. This function checks Katana to see if the project has been modified since the previous save and if nothing has been modified, stops Katana from continuously saving.
For more information on autosaving functions in Katana, please review the Katana Developer Guide.
ATTACHMENTS
We're sorry to hear that
Please tell us why