def post_context_change(self, old_context, new_context): """ Handles post-context-change requirements for Nuke, Hiero, and Nuke Studio. :param old_context: The sgtk.context.Context being switched away from. :param new_context: The sgtk.context.Context being switched to. """ # As we've changed contexts, we should update our environment variables so that if we spawn a new nuke instance # it will start up in the same environment. self.pre_app_init_nuke() # Make sure the callbacks are updated based one the current environment settings. # (for example they may be enabled or disabled in the new environment.) import tk_nuke tk_nuke.tank_ensure_callbacks_registered(engine=self) self.logger.debug("tk-nuke context changed to %s", str(new_context)) # We also need to run the post init for Nuke, which will handle # getting any gizmos setup. if not self.hiero_enabled: self.post_app_init_nuke() if self.has_ui and self._context_change_menu_rebuild: self.menu_generator.create_menu()
def pre_app_init(self): """ Called at startup, but after QT has been initialized """ # note! not using the import as this confuses nuke's calback system # (several of the key scene callbacks are in the main init file...) import tk_nuke # make sure callbacks tracking the context switching are active tk_nuke.tank_ensure_callbacks_registered()
def pre_app_init(self): """ Sets up the engine into an operational state. This method called before any apps are loaded. """ self.logger.debug("%s: Initializing...", self) import tk_nuke tk_nuke.tank_ensure_callbacks_registered(engine=self) # We need to check to make sure that we are using one of the # supported versions of Nuke. Right now that is anything between # 6.3v5 and 9.0v*. For versions higher than what we know we # support we'll simply warn and continue. For older versions # we will have to bail out, as we know they won't work properly. nuke_version = ( nuke.env.get("NukeVersionMajor"), nuke.env.get("NukeVersionMinor"), nuke.env.get("NukeVersionRelease") ) msg = "Nuke 7.0v10 is the minimum version supported!" if nuke_version[0] < 7: self.logger.error(msg) return elif nuke_version[0] == 7 and nuke_version[1] == 0 and nuke_version[2] < 10: self.logger.error(msg) return # Versions > 10.5 have not yet been tested so show a message to that effect. if nuke_version[0] > 12 or (nuke_version[0] == 12 and nuke_version[1] > 0): # This is an untested version of Nuke. msg = ("The Shotgun Pipeline Toolkit has not yet been fully tested with Nuke %d.%dv%d. " "You can continue to use the Toolkit but you may experience bugs or " "instability. Please report any issues you see to [email protected]" % (nuke_version[0], nuke_version[1], nuke_version[2])) # Show nuke message if in UI mode, this is the first time the engine has been started # and the warning dialog isn't overriden by the config. Note that nuke.message isn't # available in Hiero, so we have to skip this there. if ( self.has_ui and "TANK_NUKE_ENGINE_INIT_NAME" not in os.environ and nuke_version[0] >= self.get_setting("compatibility_dialog_min_version", 11) and not self.hiero_enabled ): nuke.message("Warning - Shotgun Pipeline Toolkit!\n\n%s" % msg) # Log the warning. self.logger.warning(msg) # Make sure we are not running Nuke PLE or Non-Commercial! if nuke.env.get("ple"): self.logger.error("The Nuke Engine does not work with Nuke PLE!") return elif nuke.env.get("nc"): self.logger.error("The Nuke Engine does not work with Nuke Non-Commercial!") return # Now check that we are at least in a project context. Note that plugin mode # does not require this check since it can operate at the site level. if not self.in_plugin_mode and self.context.project is None: # Must have at least a project in the context to even start! raise tank.TankError("The nuke engine needs at least a project " "in the context in order to start! Your " "context: %s" % self.context) # Do our mode-specific initializations. if self.hiero_enabled: self.pre_app_init_hiero() elif self.studio_enabled: self.pre_app_init_studio() else: self.pre_app_init_nuke()
def handle_new_tank_session(): import tk_nuke tk_nuke.tank_ensure_callbacks_registered() tk_nuke.tank_startup_node_callback()
def handle_new_tank_session(): import tk_nuke # Ensure the engine has been restarted before registering callback since # callbacks registration depend on engine setting. tk_nuke.tank_startup_node_callback() tk_nuke.tank_ensure_callbacks_registered()
def handle_new_tank_session(): import tk_nuke tk_nuke.tank_ensure_callbacks_registered()
def init_engine(self): # note! not using the import as this confuses nuke's calback system # (several of the key scene callbacks are in the main init file...) import tk_nuke self.log_debug("%s: Initializing..." % self) # now check that there is a location on disk which corresponds to the context if self.context.project is None: # must have at least a project in the context to even start! raise tank.TankError("The nuke engine needs at least a project in the context " "in order to start! Your context: %s" % self.context) # make sure we are not running that bloody nuke PLE! if nuke.env.get("ple") == True: self.log_error("The Nuke Engine does not work with the Nuke PLE!") return # make sure that nuke has a higher version than 6.3v5 # this is because of pyside nuke_version = (nuke.env.get("NukeVersionMajor"), nuke.env.get("NukeVersionMinor"), nuke.env.get("NukeVersionRelease")) if nuke_version[0] < 6: self.log_error("Nuke 6.3v5 is the minimum version supported!") return elif (nuke_version[0] == 6 and nuke_version[1] < 3): self.log_error("Nuke 6.3v5 is the minimum version supported!") return elif (nuke_version[0] == 6 and nuke_version[1] == 3 and nuke_version[2] < 5): self.log_error("Nuke 6.3v5 is the minimum version supported!") return # keep track of if a UI exists self._ui_enabled = nuke.env.get("gui") # versions > 7.x have not yet been tested so show a message to that effect: if nuke_version[0] > 7: # this is an untested version of Nuke msg = ("The Shotgun Pipeline Toolkit has not yet been fully tested with Nuke %d.%dv%d. " "You can continue to use the Toolkit but you may experience bugs or " "instability. Please report any issues you see to [email protected]" % (nuke_version[0], nuke_version[1], nuke_version[2])) # show nuke message if in UI mode, this is the first time the engine has been started # and the warning dialog isn't overriden by the config: if (self._ui_enabled and not "TANK_NUKE_ENGINE_INIT_NAME" in os.environ and nuke_version[0] >= self.get_setting("compatibility_dialog_min_version", 8)): nuke.message("Warning - Shotgun Pipeline Toolkit!\n\n%s" % msg) # and log the warning self.log_warning(msg) # now prepare tank so that it will be picked up by any new processes # created by file->new or file->open. # Store data needed for bootstrapping Tank in env vars. Used in startup/menu.py os.environ["TANK_NUKE_ENGINE_INIT_NAME"] = self.instance_name os.environ["TANK_NUKE_ENGINE_INIT_CONTEXT"] = yaml.dump(self.context) os.environ["TANK_NUKE_ENGINE_INIT_PROJECT_ROOT"] = self.tank.project_path # add our startup path to the nuke init path startup_path = os.path.abspath(os.path.join( os.path.dirname(__file__), "startup")) tank.util.append_path_to_env_var("NUKE_PATH", startup_path) # we also need to pass the path to the python folder down to the init script # because nuke python does not have a __file__ attribute for that file local_python_path = os.path.abspath(os.path.join( os.path.dirname(__file__), "python")) os.environ["TANK_NUKE_ENGINE_MOD_PATH"] = local_python_path # make sure callbacks tracking the context switching are active tk_nuke.tank_ensure_callbacks_registered()
return if not "TANK_ENGINE" in os.environ: output_handle("Shotgun: Unable to determine engine to start!") return engine_name = os.environ.get("TANK_ENGINE") try: context = tank.context.deserialize(os.environ.get("TANK_CONTEXT")) except Exception, e: output_handle("Shotgun: Could not create context! " "Shotgun Toolkit will be disabled. Details: %s" % str(e)) return try: engine = tank.platform.start_engine(engine_name, context.tank, context) except Exception, e: output_handle("Shotgun: Could not start engine: %s" % str(e)) return path = os.environ.get("TANK_NUKE_ENGINE_MOD_PATH") if path: sys.path.append(path) import tk_nuke tk_nuke.tank_ensure_callbacks_registered() else: output_handle("Shotgun could not find the environment variable TANK_NUKE_ENGINE_MOD_PATH!") bootstrap_sgtk()
if not "TANK_ENGINE" in os.environ: output_handle("Shotgun: Unable to determine engine to start!") return engine_name = os.environ.get("TANK_ENGINE") try: context = tank.context.deserialize(os.environ.get("TANK_CONTEXT")) except Exception, e: output_handle("Shotgun: Could not create context! " "Shotgun Toolkit will be disabled. Details: %s" % str(e)) return try: engine = tank.platform.start_engine(engine_name, context.tank, context) except Exception, e: output_handle("Shotgun: Could not start engine: %s" % str(e)) return path = os.environ.get("TANK_NUKE_ENGINE_MOD_PATH") if path: sys.path.append(path) import tk_nuke tk_nuke.tank_ensure_callbacks_registered() else: output_handle( "Shotgun could not find the environment variable TANK_NUKE_ENGINE_MOD_PATH!" ) bootstrap_sgtk()
def init_engine(self): # note! not using the import as this confuses nuke's calback system # (several of the key scene callbacks are in the main init file...) import tk_nuke self.log_debug("%s: Initializing..." % self) # now check that there is a location on disk which corresponds to the context if self.context.project is None: # must have at least a project in the context to even start! raise tank.TankError( "The nuke engine needs at least a project in the context " "in order to start! Your context: %s" % self.context) # make sure we are not running that bloody nuke PLE! if nuke.env.get("ple") == True: self.log_error("The Nuke Engine does not work with the Nuke PLE!") return # make sure that nuke has a higher version than 6.3v5 # this is because of pyside nuke_version = (nuke.env.get("NukeVersionMajor"), nuke.env.get("NukeVersionMinor"), nuke.env.get("NukeVersionRelease")) if nuke_version[0] < 6: self.log_error("Nuke 6.3v5 is the minimum version supported!") return elif (nuke_version[0] == 6 and nuke_version[1] < 3): self.log_error("Nuke 6.3v5 is the minimum version supported!") return elif (nuke_version[0] == 6 and nuke_version[1] == 3 and nuke_version[2] < 5): self.log_error("Nuke 6.3v5 is the minimum version supported!") return # keep track of if a UI exists self._ui_enabled = nuke.env.get("gui") # versions > 8.0 have not yet been tested so show a message to that effect: if nuke_version[0] > 8 or (nuke_version[0] == 8 and nuke_version[1] > 0): # this is an untested version of Nuke msg = ( "The Shotgun Pipeline Toolkit has not yet been fully tested with Nuke %d.%dv%d. " "You can continue to use the Toolkit but you may experience bugs or " "instability. Please report any issues you see to [email protected]" % (nuke_version[0], nuke_version[1], nuke_version[2])) # show nuke message if in UI mode, this is the first time the engine has been started # and the warning dialog isn't overriden by the config: if (self._ui_enabled and not "TANK_NUKE_ENGINE_INIT_NAME" in os.environ and nuke_version[0] >= self.get_setting( "compatibility_dialog_min_version", 9)): nuke.message("Warning - Shotgun Pipeline Toolkit!\n\n%s" % msg) # and log the warning self.log_warning(msg) # now prepare tank so that it will be picked up by any new processes # created by file->new or file->open. # Store data needed for bootstrapping Tank in env vars. Used in startup/menu.py os.environ["TANK_NUKE_ENGINE_INIT_NAME"] = self.instance_name os.environ["TANK_NUKE_ENGINE_INIT_CONTEXT"] = yaml.dump(self.context) os.environ[ "TANK_NUKE_ENGINE_INIT_PROJECT_ROOT"] = self.tank.project_path # add our startup path to the nuke init path startup_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "startup")) tank.util.append_path_to_env_var("NUKE_PATH", startup_path) # we also need to pass the path to the python folder down to the init script # because nuke python does not have a __file__ attribute for that file local_python_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "python")) os.environ["TANK_NUKE_ENGINE_MOD_PATH"] = local_python_path # make sure callbacks tracking the context switching are active tk_nuke.tank_ensure_callbacks_registered()