Skip to content

Commit

Permalink
Merge pull request #5107 from ynput/bugfix/OP-4096_Nuke-open_file-fun…
Browse files Browse the repository at this point in the history
…ction-wouldnt-open-autosave-file
  • Loading branch information
mkolar committed Jun 26, 2023
2 parents 6f7f633 + cbf21cf commit 53f5fc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion openpype/hosts/nuke/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import nuke

from openpype import resources
from .lib import maintained_selection
from qtpy import QtWidgets


def set_context_favorites(favorites=None):
Expand Down Expand Up @@ -55,6 +55,7 @@ def bake_gizmos_recursively(in_group=None):
Arguments:
is_group (nuke.Node)[optonal]: group node or all nodes
"""
from .lib import maintained_selection
if in_group is None:
in_group = nuke.Root()
# preserve selection after all is done
Expand Down Expand Up @@ -129,3 +130,11 @@ def get_colorspace_list(colorspace_knob):
reduced_clrs.append(clrs)

return reduced_clrs


def is_headless():
"""
Returns:
bool: headless
"""
return QtWidgets.QApplication.instance() is None
7 changes: 7 additions & 0 deletions openpype/hosts/nuke/api/workio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Host API required Work Files tool"""
import os
import nuke
from .utils import is_headless


def file_extensions():
Expand All @@ -25,6 +26,12 @@ 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()
if not is_headless():
autosave = nuke.toNode("preferences")["AutoSaveName"].evaluate()
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)
nuke.Root()["name"].setValue(filepath)
nuke.Root()["project_directory"].setValue(os.path.dirname(filepath))
Expand Down

0 comments on commit 53f5fc6

Please sign in to comment.