From c581f72e76daf5db776742c83161a0f03e77aac8 Mon Sep 17 00:00:00 2001 From: Ricardo Musch Date: Wed, 8 Oct 2025 00:29:40 +0100 Subject: [PATCH 1/2] Add a setting to suppress the minimum supported Nuke version Dialog as it blocks the startup of Nuke and makes this annoying in daily use. --- engine.py | 67 ++++++++++++++++++++++++++++--------------------------- info.yml | 7 ++++++ 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/engine.py b/engine.py index 79c0040..f91d5fd 100644 --- a/engine.py +++ b/engine.py @@ -240,41 +240,42 @@ def pre_app_init(self): ) if self.has_ui: - sgtk.platform.qt.QtGui.QMessageBox.warning( - # Use QMessageBox instead of nuke.message because: - # - nuke.message is not available in Hiero - # - nuke.message doesn't allow to set the title - # Overall, this is a better user experience - None, # parent - "Warning - Flow Production Tracking Compatibility!".ljust( - # Padding to try to prevent the dialog being insanely narrow - 70 - ), - """ -Flow Production Tracking no longer supports {product} versions older than -{version}. -You can continue to use Toolkit but you may experience bugs or instabilities. - -For information regarding support engine versions, please visit this page: -{url_doc_supported_versions} - """.strip() - .replace( - # Presence of \n breaks the Rich Text Format - "\n", - "
", - ) - .format( - product="Nuke", - url_doc_supported_versions='{u}'.format( - u=url_doc_supported_versions, - color=sgtk.platform.constants.SG_STYLESHEET_CONSTANTS.get( - "SG_HIGHLIGHT_COLOR", - "#18A7E3", + if self.get_setting("display_min_supported_version_warning_dialog"): + sgtk.platform.qt.QtGui.QMessageBox.warning( + # Use QMessageBox instead of nuke.message because: + # - nuke.message is not available in Hiero + # - nuke.message doesn't allow to set the title + # Overall, this is a better user experience + None, # parent + "Warning - Flow Production Tracking Compatibility!".ljust( + # Padding to try to prevent the dialog being insanely narrow + 70 + ), + """ + Flow Production Tracking no longer supports {product} versions older than + {version}. + You can continue to use Toolkit but you may experience bugs or instabilities. + + For information regarding support engine versions, please visit this page: + {url_doc_supported_versions} + """.strip() + .replace( + # Presence of \n breaks the Rich Text Format + "\n", + "
", + ) + .format( + product="Nuke", + url_doc_supported_versions='{u}'.format( + u=url_doc_supported_versions, + color=sgtk.platform.constants.SG_STYLESHEET_CONSTANTS.get( + "SG_HIGHLIGHT_COLOR", + "#18A7E3", + ), ), + version=self.version_str(VERSION_OLDEST_SUPPORTED), ), - version=self.version_str(VERSION_OLDEST_SUPPORTED), - ), - ) + ) elif nuke_version <= VERSION_NEWEST_SUPPORTED: # Within the range of supported versions diff --git a/info.yml b/info.yml index 4f535a6..58e3d3a 100644 --- a/info.yml +++ b/info.yml @@ -159,6 +159,13 @@ configuration: value to the current major version + 1." default_value: 16 + display_min_supported_version_warning_dialog: + type: bool + description: "Controls whether a warning should display if the nuke version is below the minimum supported, + but above the minimum required, version. Defaults to True. Set to False to disable the GUI + warning so this doesn't interrupt the loading of the application." + default_value: True + # the Shotgun fields that this engine needs in order to operate correctly requires_shotgun_fields: From c1ca4085b61c3963fbe57d1dd9574d73d2c65ac6 Mon Sep 17 00:00:00 2001 From: Ricardo Musch Date: Tue, 11 Nov 2025 05:22:31 +0000 Subject: [PATCH 2/2] Restore the context from deserialized root knob data if this exists in the script. This is better than getting the context from the path as the path usually doesn't include the Task name/id. --- python/tk_nuke/__init__.py | 64 +++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/python/tk_nuke/__init__.py b/python/tk_nuke/__init__.py index 0716e35..eadd646 100644 --- a/python/tk_nuke/__init__.py +++ b/python/tk_nuke/__init__.py @@ -155,11 +155,53 @@ def __sgtk_on_save_callback(): # now restart the engine with the new context __engine_refresh(new_ctx) + # Ensure that the sgtk tab and sgtk_context knob exist on the root node. + __ensure_sgtk_tab_and_context() + + # save the context into the sgtk_context knob + root = nuke.root() + if "sgtk_context" in root.knobs(): + context_knob = root.knob("sgtk_context") + context_str = new_ctx.serialize(with_user_credentials=False, use_json=False) + context_knob.setValue(context_str) + logger.debug("Updated 'sgtk_context' knob with value: %s" % context_str) + except Exception: logger.exception("An exception was raised during addOnScriptSave callback.") __create_tank_error_menu() +def __ensure_sgtk_tab_and_context(): + """ + Ensure that the sgtk tab and sgtk_context knob exist on the root node. + 1. If the "sgtk" tab does not exist, create it. + 2. If the "sgtk_context" knob does not exist, create it. + 3. Log actions taken. + """ + logger.debug("Ensuring 'sgtk' tab and 'sgtk_context' knob exist on root node.") + + try: + root = nuke.root() + + # Check if the "sgtk" tab exists + if "sgtk" not in root.knobs(): + sgtk_tab = nuke.Tab_Knob("sgtk", "sgtk") + root.addKnob(sgtk_tab) + logger.debug("Created 'sgtk' tab on root.") + else: + logger.debug("'sgtk' tab already exists.") + + # Check if the sgtk_context knob exists + if "sgtk_context" not in root.knobs(): + context_knob = nuke.String_Knob("sgtk_context", "ShotGrid Context") + root.addKnob(context_knob) + logger.debug("Created 'sgtk_context' knob.") + else: + logger.debug("'sgtk_context' knob already exists.") + except Exception as e: + logger.exception("Failed to ensure 'sgtk' tab and 'sgtk_context' knob: %s", e) + + def sgtk_on_load_callback(): """ Callback that fires every time a script is loaded. @@ -217,7 +259,26 @@ def sgtk_on_load_callback(): if sgtk.platform.current_engine(): curr_ctx = sgtk.platform.current_engine().context - logger.debug("") + logger.debug("Trying to get the context from the root.sgtk_context knob if it exists...") + # Try to get the context from the root.sgtk_context knob if it exists + root = nuke.root() + if "sgtk_context" in root.knobs(): + context_knob = root.knob("sgtk_context") + context_str_serialized = context_knob.value() + if context_str_serialized: + logger.debug("Found serialized context in knob: %s" % context_str_serialized) + try: + new_ctx = sgtk.Context.deserialize(context_str_serialized) + logger.debug("Deserialized context from knob: %r" % (new_ctx,)) + # Now switch to the context appropriate for the file + __engine_refresh(new_ctx) + return + except Exception as e: + logger.debug( + "Could not deserialize context from knob: %s" % (e,) + ) + + logger.debug("Computing new context from file path...") new_ctx = tk.context_from_path(file_name, curr_ctx) logger.debug("Current context: %r" % (curr_ctx,)) logger.debug("New context: %r" % (new_ctx,)) @@ -274,3 +335,4 @@ def tank_ensure_callbacks_registered(engine=None): nuke.removeOnScriptLoad(sgtk_on_load_callback) nuke.removeOnScriptSave(__sgtk_on_save_callback) g_tank_callbacks_registered = False +