def refresh_engine(engine_name, prev_context, menu_name): """ refresh the current engine """ #import rpdb2;rpdb2.start_embedded_debugger("12345") current_engine = tank.platform.current_engine() # first make sure that the disabled menu is reset, if it exists... #if pm.menu("ShotgunMenuDisabled", exists=True): # pm.deleteUI("ShotgunMenuDisabled") # if the scene opened is actually a file->new, then maintain the current # context/engine. scene_name = lxtd.current_scene().filename if not scene_name: return current_engine new_path = scene_name # this file could be in another project altogether, so create a new Tank # API instance. try: tk = tank.tank_from_path(new_path) except tank.TankError, e: # render menu modoshotgunsupport.add_disabled_menu() # (AD) - this leaves the engine running - is this correct? return current_engine
if current_engine: current_engine.log_debug( "Ready to switch to context because of scene event !") current_engine.log_debug("Prev context: %s" % prev_context) current_engine.log_debug("New context: %s" % ctx) # tear down existing engine current_engine.destroy() # create new engine try: new_engine = tank.platform.start_engine(engine_name, tk, ctx) except tank.TankEngineInitError, e: log_msg("Shotgun: Engine cannot be started: %s" % e) # render menu modoshotgunsupport.add_disabled_menu() return None else: new_engine.log_debug("Launched new engine for context!") return new_engine def on_scene_event_callback(engine_name, prev_context, menu_name): """ Callback that's run whenever a scene is saved or opened. """ new_engine = None try: new_engine = refresh_engine(engine_name, prev_context, menu_name)
if current_engine: current_engine.log_debug("Ready to switch to context because of scene event !") current_engine.log_debug("Prev context: %s" % prev_context) current_engine.log_debug("New context: %s" % ctx) # tear down existing engine current_engine.destroy() # create new engine try: new_engine = tank.platform.start_engine(engine_name, tk, ctx) except tank.TankEngineInitError, e: log_msg("Shotgun: Engine cannot be started: %s" % e) # render menu modoshotgunsupport.add_disabled_menu() return None else: new_engine.log_debug("Launched new engine for context!") return new_engine def on_scene_event_callback(engine_name, prev_context, menu_name): """ Callback that's run whenever a scene is saved or opened. """ new_engine = None try: new_engine = refresh_engine(engine_name, prev_context, menu_name) except Exception, e: