
Search is based on keyword.
Ex: "Procedures"
Do not search with natural language
Ex: "How do I write a new procedure?"
Q100497: Setting up an autosave script in Katana
Warning: This article contains links to external websites
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 Online Help: Katana Online Help - 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: Locating a crash Autosave file
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: 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 setting up before running functions with Python.
OPTION 1: Save over current project file
Using this option will simply 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 manually modify the script to add your desired save location.
Additionally, you will need to create a tool to check for autosave files on startup.
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 which are switched 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
Sorry you didn't find this helpful
Why wasn't this helpful? (check all that apply)
Thanks for your feedback.
If you can't find what you're looking for or you have a workflow question, please try Foundry Support.
If you have any thoughts on how we can improve our learning content, please email the Documentation team using the button below.
Thanks for taking time to give us feedback.