autosave nk script will be loaded if the script is found in the work directory

This commit is contained in:
Kayla Man 2023-06-07 15:30:59 +08:00
parent 65e5aa40cf
commit 3e02ea6263

View file

@ -25,7 +25,13 @@ def open_file(filepath):
# To remain in the same window, we have to clear the script and read
# in the contents of the workfile.
nuke.scriptClear()
nuke.scriptReadFile(filepath)
autosave = f"{filepath}.autosave"
autosave_prmpt = "Autosave detected.\nWould you like to load the autosave file?" # noqa
if os.path.isfile(autosave) and nuke.ask(autosave_prmpt):
filepath = autosave
nuke.scriptReadFile(filepath)
else:
nuke.scriptReadFile(filepath)
nuke.Root()["name"].setValue(filepath)
nuke.Root()["project_directory"].setValue(os.path.dirname(filepath))
nuke.Root().setModified(False)