diff --git a/openpype/hosts/nuke/api/utils.py b/openpype/hosts/nuke/api/utils.py index 2b3c35c23a..7b02585892 100644 --- a/openpype/hosts/nuke/api/utils.py +++ b/openpype/hosts/nuke/api/utils.py @@ -2,7 +2,7 @@ import os import nuke from openpype import resources -from .lib import maintained_selection +from qtpy import QtWidgets def set_context_favorites(favorites=None): @@ -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 @@ -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 diff --git a/openpype/hosts/nuke/api/workio.py b/openpype/hosts/nuke/api/workio.py index 5692f8e63c..8d29e0441f 100644 --- a/openpype/hosts/nuke/api/workio.py +++ b/openpype/hosts/nuke/api/workio.py @@ -1,6 +1,7 @@ """Host API required Work Files tool""" import os import nuke +from .utils import is_headless def file_extensions(): @@ -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))