概括
在Katana中设置项目时,边做边保存至关重要,以避免数据和时间的丢失。Katana Katana了自动保存功能,会在一定时间或操作后保存一个备份崩溃文件。
有关崩溃存档的更多信息,请参阅Katana用户指南: 自动存档。
本文演示了如何设置自动保存脚本,该脚本可以用于将文件保存到自定义位置并采用自定义命名约定,而不是像自动保存功能那样保存到Katana的临时目录并使用自动生成的文件名。
更多信息
Katana通过Katana Python API 中的Katana File 模块保存其项目文件。
调用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 强制执行新的崩溃保存。
虽然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变量进行切换。
根据所选选项,脚本将保存为崩溃保存文件、覆盖当前Katana文件或保存到新位置。
选项 1 和 2 首先检查另一个名为Katana File.IsFileDirty()的函数的结果。此函数检查Katana ,查看项目自上次保存以来是否已被修改;如果没有修改,则阻止Katana继续保存。
有关Katana自动保存功能的更多信息,请参阅Katana开发者指南。
附件
我们很遗憾听到
请告诉我们