概括
在Katana中设置项目时,边进行边保存对于避免数据和时间损失至关重要。 Katana具有内置的自动保存功能,可在一定时间或操作后保存备份崩溃文件。
有关崩溃保存的更多信息,请参阅Katana用户指南: 自动保存
本文演示如何设置自动保存脚本,该脚本可用于使用自定义命名约定保存到自定义位置,而不是使用自动生成的文件名保存到Katana的临时目录,这是自动保存功能的默认行为。
更多信息
Katana通过Katana Python API 中的Katana文件模块保存其项目文件。
调用Katana File.Save ( path/to/location/file.katana )将使用所选文件名将当前Katana项目保存到所选位置。
调用Katana File.CrashSave()将以自动生成的名称将当前Katana项目的崩溃文件保存到临时目录,可以使用Katana崩溃文件选择器将其恢复。
有关恢复自动保存文件的更多信息,请参阅以下文章: Q100450:如何在崩溃后查找并恢复自动保存的文件
使用上述功能,您可以创建一个 Python 脚本,该脚本会按照指定的时间间隔自动保存Katana项目。
有关Katana文件模块的更多信息,请参阅Katana开发人员指南: 使用项目
示例脚本
本文附带了一个 Python 示例,您可以根据需要下载并修改该示例。
下载示例并将文件移动到.katana\UIPlugins文件夹。
例如:
Windows: C:\Users\USERNAME\.katana\UIPlugins\autosaveProject.py
Linux: /mnt/nethome/users/USERNAME/.katana/UIPlugins/autosaveProject.py
将文件添加到 UIPlugins 文件夹后, Katana将在启动时加载并执行该文件。
使用脚本
该脚本有 3 个选项,您可以通过设置 saveOption 变量进行选择。它还具有保存间隔时间的选项,对于示例脚本,当前设置为 60000 毫秒(60 秒)。
请检查以下选项:
选项 0:强制自动保存崩溃保存
此选项允许您通过 Python 强制执行新的 CrashSave。
尽管Katana具有内置的崩溃自动保存功能,但此功能对于在使用 Python 运行函数之前进行设置非常有用。
选项 1:保存当前项目文件
使用此选项将用新的保存覆盖当前项目。
Katana仅在项目修改后才会保存文件。
选项 2:将文件保存到指定位置
此选项的工作方式与选项 1 相同,但允许您选择目录位置和名称。
您将需要更改脚本以添加所需的保存位置。
此外,您需要创建一个工具来在启动时检查自动保存文件。
from Katana import QtCore, NodegraphAPI, Katana File
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 Katana File.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)
脚本说明
该脚本使用QtCore.QTimer()
调用来提供计时器循环。使用QTimer允许后台函数在执行脚本函数之前等待一定的时间。
每次经过指定的时间量(由autosaveDelay变量确定)时,计时器都会运行saveAndSubmit()
函数。
在saveAndSubmit()
函数定义中,有 3 个选项可以使用saveOption变量进行切换。
根据所选的选项,脚本将另存为 crashSave、保存在当前Katana文件上或保存在新位置。
选项 1 和 2 首先检查另一个名为Katana File.IsFileDirty()
的函数的结果。此函数检查Katana以查看自上次保存以来项目是否已被修改,如果没有任何修改,则停止Katana继续保存。
有关Katana中自动保存功能的更多信息,请查看Katana开发人员指南。
附件
我们很遗憾听到
请告诉我们