def projectFavorites(): entity = ft_utils.get_entity() root = entity.getProject().getRoot() try: paths = ft_utils.getAllPathsYaml(entity) except: print 'this project is not yet supported' return if 'ASSET_BUILD' in os.environ.keys(): pathNameMapping = { 'asset.task.work': 'Task work', 'asset.render': 'Task output', } else: pathNameMapping = { 'shot.task.work': 'Task work', 'shot.render': 'Task output', } icon_path = os.path.join(os.environ['PIPELINE_IMAGES'], 'ft_logo.png') for path in paths: if path[1].name in pathNameMapping.keys(): niceName = pathNameMapping.get(path[1].name, None) nuke.removeFavoriteDir(niceName) path_to_add = os.path.join(root, path[0]) os.environ[niceName] = path_to_add nuke.addFavoriteDir(niceName, path_to_add, nuke.IMAGE | nuke.SCRIPT | nuke.GEO, icon=icon_path)
def reset_environment(self): token_dict = environment.get_token_dict() self.debug_msg("token dict: " + str(token_dict)) for token in token_dict: favorite_name = self.get_favorite_name(token, token_dict[token]) self.debug_msg("removing " + favorite_name) nuke.removeFavoriteDir(favorite_name)
def setFavorites(self): # add project specific shortcuts nuke.addFavoriteDir('Desktop', 'C:/Users/' + os.environ['USERNAME'] + '/Desktop') nuke.addFavoriteDir('RB','//grey09/rugbybugs/') nuke.addFavoriteDir('RB_SHOTS', '//grey09/rugbybugs/Production/2d/comp/') nuke.addFavoriteDir('RB_RnD', self.getPersonalRndFolder()) # remove generic favorites nuke.removeFavoriteDir("Home") nuke.removeFavoriteDir("Root") nuke.removeFavoriteDir("Nuke") nuke.removeFavoriteDir("Current")
def __setup_favourite_dirs(self): """ Sets up nuke shortcut "favourite dirs" that are presented in the left hand side of nuke common dialogs (open, save) """ engine_root_dir = self.disk_location tank_logo_small = os.path.abspath(os.path.join(engine_root_dir, "resources", "logo_color_16.png")) # old versions were referring to these favourites - so keep them around to make # sure there are no old leftovers in the system... supported_entity_types = ["Shot", "Sequence", "Scene", "Asset", "Project"] for x in supported_entity_types: nuke.removeFavoriteDir("Tank Current %s" % x) #handle project proj = self.context.project paths = self.tank.paths_from_entity(proj["type"], proj["id"]) pipeline_config=tank.pipelineconfig.from_path(paths[0]) for path in paths: #getting root names if the paths are the same dirname='Unknown Path' if path in pipeline_config.get_data_roots().values(): #comparing roots paths with input path for rootname, rootpath in pipeline_config.get_data_roots().items(): if rootpath == path: dirname=rootname #removing old directory nuke.removeFavoriteDir(dirname) #adding new path nuke.addFavoriteDir(dirname, directory=path, type=(nuke.IMAGE|nuke.SCRIPT|nuke.GEO), icon=tank_logo_small, tooltip=path) #handle favourites directories for directory in self.get_setting("favorite_directories"): #removing old directory nuke.removeFavoriteDir(directory['display_name']) #getting paths from context template=self.get_template_by_name(directory['directory']) fields=self.context.as_template_fields(template) p=template.apply_fields(fields) #adding new directory nuke.addFavoriteDir(directory['display_name'], directory=p, type=(nuke.IMAGE|nuke.SCRIPT|nuke.GEO), icon=directory['icon'], tooltip=p)
def set_workspace(self, directory): import nuke from construct_ui import resources ctx = construct.get_context() fav_icon = resources.path(':/brand/construct_icon-white-on-black') favs = ['project', 'sequence', 'shot', 'asset', 'workspace'] for fav in favs: fav_name = fav.title() nuke.removeFavoriteDir(fav_name) entry = ctx[fav] if entry: directory = entry.path nuke.addFavoriteDir(fav_name, directory=directory, type=(nuke.IMAGE | nuke.SCRIPT | nuke.GEO), icon=fav_icon, tooltip=directory) os.chdir(directory) nuke.root()['project_directory'].setValue(directory)
def __setup_favorite_dirs(self): """ Sets up nuke shortcut "favorite dirs" that are presented in the left hand side of Nuke common dialogs (open, save). Nuke currently only writes favorites to disk in ~/.nuke/folders.nk. If you add/remove one in the UI. Doing them via the api only updates them for the session (Nuke bug #3740). See http://forums.thefoundry.co.uk/phpBB2/viewtopic.php?t=3481&start=15 """ engine_root_dir = self.disk_location sg_logo = os.path.abspath(os.path.join(engine_root_dir, "resources", "sg_logo_80px.png")) # Ensure old favorites we used to use are removed. supported_entity_types = ["Shot", "Sequence", "Scene", "Asset", "Project"] for x in supported_entity_types: nuke.removeFavoriteDir("Tank Current %s" % x) nuke.removeFavoriteDir("Tank Current Work") nuke.removeFavoriteDir("Shotgun Current Project") nuke.removeFavoriteDir("Shotgun Current Work") # Add favorties for current project root(s). proj = self.context.project current_proj_fav = self.get_setting("project_favourite_name") # Only add these current project entries if we have a value from settings. # Otherwise, they have opted to not show them. if proj and current_proj_fav: proj_roots = self.tank.roots for root_name, root_path in proj_roots.items(): dir_name = current_proj_fav if len(proj_roots) > 1: dir_name += " (%s)" % root_name # Remove old directory nuke.removeFavoriteDir(dir_name) # Add new path nuke.addFavoriteDir(dir_name, directory=root_path, type=(nuke.IMAGE | nuke.SCRIPT | nuke.GEO), icon=sg_logo, tooltip=root_path) # Add favorites directories from the config for favorite in self.get_setting("favourite_directories"): # Remove old directory nuke.removeFavoriteDir(favorite['display_name']) try: template = self.get_template_by_name(favorite['template_directory']) fields = self.context.as_template_fields(template) path = template.apply_fields(fields) except Exception as e: msg = "Error processing template '%s' to add to favorite " \ "directories: %s" % (favorite['template_directory'], e) self.logger.exception(msg) continue # Add new directory icon_path = favorite.get('icon') if not os.path.isfile(icon_path) or not os.path.exists(icon_path): icon_path = sg_logo nuke.addFavoriteDir(favorite['display_name'], directory=path, type=(nuke.IMAGE | nuke.SCRIPT | nuke.GEO), icon=icon_path, tooltip=path)
def __setup_favorite_dirs(self): """ Sets up nuke shortcut "favorite dirs" that are presented in the left hand side of Nuke common dialogs (open, save). Nuke currently only writes favorites to disk in ~/.nuke/folders.nk. If you add/remove one in the UI. Doing them via the api only updates them for the session (Nuke bug #3740). See http://forums.thefoundry.co.uk/phpBB2/viewtopic.php?t=3481&start=15 """ engine_root_dir = self.disk_location sg_logo = os.path.abspath(os.path.join(engine_root_dir, "resources", "sg_logo_80px.png")) # Ensure old favorites we used to use are removed. supported_entity_types = ["Shot", "Sequence", "Scene", "Asset", "Project"] for x in supported_entity_types: nuke.removeFavoriteDir("Tank Current %s" % x) nuke.removeFavoriteDir("Tank Current Work") nuke.removeFavoriteDir("Shotgun Current Project") nuke.removeFavoriteDir("Shotgun Current Work") # Add favorties for current project root(s). proj = self.context.project current_proj_fav = self.get_setting("project_favourite_name") # Only add these current project entries if we have a value from settings. # Otherwise, they have opted to not show them. if proj and current_proj_fav: proj_roots = self.tank.roots for root_name, root_path in proj_roots.items(): dir_name = current_proj_fav if len(proj_roots) > 1: dir_name += " (%s)" % root_name # Remove old directory nuke.removeFavoriteDir(dir_name) # Add new path nuke.addFavoriteDir(dir_name, directory=root_path, type=(nuke.IMAGE|nuke.SCRIPT|nuke.GEO), icon=sg_logo, tooltip=root_path) # Add favorites directories from the config for favorite in self.get_setting("favourite_directories"): # Remove old directory nuke.removeFavoriteDir(favorite['display_name']) try: template = self.get_template_by_name(favorite['template_directory']) fields = self.context.as_template_fields(template) path = template.apply_fields(fields) except Exception, e: msg = "Error processing template '%s' to add to favorite " \ "directories: %s" % (favorite['template_directory'], e) self.log_exception(msg) continue # Add new directory icon_path = favorite.get('icon') if not os.path.isfile(icon_path) or not os.path.exists(icon_path): icon_path = sg_logo nuke.addFavoriteDir(favorite['display_name'], directory=path, type=(nuke.IMAGE|nuke.SCRIPT|nuke.GEO), icon=icon_path, tooltip=path)
def setFavorites(self): nuke.removeFavoriteDir('Nuke') nuke.addFavoriteDir('DotNuke', os.path.expanduser('~/.nuke'), 0) nuke.addFavoriteDir('Jobs', '/', 0) nuke.addFavoriteDir('Fonts', '/', nuke.FONT)
def init_shot_env(): global config homedir = os.path.expanduser('~') logfile = "" if sys.platform == 'win32': logfile = os.path.join(homedir, 'AppData', 'Local', 'IHPipeline', 'nuke_launch.log') elif sys.platform == 'darwin': logfile = os.path.join(homedir, 'Library', 'Logs', 'IHPipeline', 'nuke_launch.log') elif sys.platform == 'linux2': logfile = os.path.join(homedir, 'Logs', 'IHPipeline', 'nuke_launch.log') if not os.path.exists(os.path.dirname(logfile)): os.makedirs(os.path.dirname(logfile)) logFormatter = logging.Formatter( "%(asctime)s:[%(threadName)s]:[%(levelname)s]:%(message)s") log = logging.getLogger() log.setLevel(logging.DEBUG) fileHandler = logging.FileHandler(logfile) fileHandler.setFormatter(logFormatter) log.addHandler(fileHandler) consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(logFormatter) log.addHandler(consoleHandler) script_path = os.path.normpath(nuke.root().name()) script_path_lst = script_path.split(os.path.sep) path_idx = 0 str_show_code = None str_shot = None str_seq = None try: str_show_code = os.environ['IH_SHOW_CODE'] except KeyError: log.warning( "IH_SHOW_CODE environment variable not defined. Proceeding without environment." ) return str_show_root = None try: str_show_root = os.environ['IH_SHOW_ROOT'] except KeyError: log.warning( "IH_SHOW_ROOT environment variable not defined. Proceeding without environment." ) return if not os.path.exists(str_show_root): log.warning("Show root directory does not exist at %s." % str_show_root) return cfg_shot_dir = config.get(str_show_code, 'shot_dir_format') cfg_seq_dir = config.get(str_show_code, 'seq_dir_format') cfg_shot_regexp = config.get(str_show_code, 'shot_regexp') cfg_seq_regexp = config.get(str_show_code, 'sequence_regexp') # were we called from within shotgun? b_shotgun = False b_shotgun_res = False engine = None ctx = None entity = None for envvar in os.environ.keys(): log.debug('ENVIRONMENT - %s: %s' % (envvar, os.environ[envvar])) try: toolkit_engine = os.environ['TANK_ENGINE'] b_shotgun = True log.info( 'Setting b_shotgun to True, os.environ[\'TANK_ENGINE\'] exists.') except: pass if not script_path.startswith(str_show_root): log.warning( "Unable to match show root directory with Nuke script path.") b_shotgun_res = True matchobject = re.search(cfg_shot_regexp, script_path) # make sure this file matches the shot pattern if not matchobject: log.warning( "This script name does not match the shot regular expression pattern for the show." ) b_shotgun_res = True else: str_shot = matchobject.group(0) str_seq = re.search(cfg_seq_regexp, str_shot).group(0) if b_shotgun: log.info("Nuke executed from within Shotgun Desktop Integration.") ctx = None try: import sgtk ctx = sgtk.Context.deserialize(os.environ['TANK_CONTEXT']) except KeyError: log.error("Envionrment variable TANK_CONTEXT not found.") except ImportError: log.error("Unable to import sgtk.") if ctx == None: log.warning( "Nuke executed within Shotgun, but the context associated with the current engine is None." ) else: log.info("Shotgun Toolkit Context Object:") log.info(ctx) entity = ctx.entity if entity == None: log.warning( "Nuke executed within Shotgun, but the entity associated with the current context is None." ) else: if entity['type'] != 'Shot': log.warning( "Nuke executed within Shotgun, but not in the context of a specific shot." ) else: if b_shotgun_res: log.info( "Nuke executed within Shotgun, but no active script available. Setting sequence and shot from current engine context." ) try: str_shot = entity['name'] str_seq = re.search(cfg_seq_regexp, str_shot).group(0) except KeyError: log.error( "For some reason, context provided by Shotgun to Nuke is %s. Unable to proceed." % ctx) str_shot = None if str_shot == None: log.warning( "Could not determine current shot from script name, or from database. Exiting init_shot_env()." ) return str_seq = re.search(cfg_seq_regexp, str_shot).group(0) log.info('Sequence is %s' % str_seq) log.info('Shot is %s' % str_shot) str_seq_path = "" str_shot_path = "" str_show_path = str_show_root str_shot_path = cfg_shot_dir.format(show_root=str_show_path, pathsep=os.path.sep, sequence=str_seq, shot=str_shot) str_seq_path = cfg_seq_dir.format(show_root=str_show_path, pathsep=os.path.sep, sequence=str_seq) str_show = str_show_code log.info("Located show %s, path %s" % (str_show, str_show_path)) log.info("Located sequence %s, path %s" % (str_seq, str_seq_path)) log.info("Located shot %s, path %s" % (str_shot, str_shot_path)) os.environ['SHOW'] = str_show os.environ['SHOW_PATH'] = str_show_path os.environ['SEQ'] = str_seq os.environ['SEQ_PATH'] = str_seq_path os.environ['SHOT'] = str_shot os.environ['SHOT_PATH'] = str_shot_path # add knobs to root, if they don't exist already root_knobs_dict = nuke.root().knobs() k_ih_tab = None k_ih_show = None k_ih_show_path = None k_ih_seq = None k_ih_seq_path = None k_ih_shot = None k_ih_shot_path = None try: k_ih_tab = root_knobs_dict['tab_inhouse'] except KeyError: k_ih_tab = nuke.Tab_Knob('tab_inhouse', 'In-House') nuke.root().addKnob(k_ih_tab) try: k_ih_show = root_knobs_dict['txt_ih_show'] except KeyError: k_ih_show = nuke.String_Knob('txt_ih_show', 'show') nuke.root().addKnob(k_ih_show) try: k_ih_show_path = root_knobs_dict['txt_ih_show_path'] except KeyError: k_ih_show_path = nuke.String_Knob('txt_ih_show_path', 'show path') nuke.root().addKnob(k_ih_show_path) try: k_ih_seq = root_knobs_dict['txt_ih_seq'] except KeyError: k_ih_seq = nuke.String_Knob('txt_ih_seq', 'sequence') nuke.root().addKnob(k_ih_seq) try: k_ih_seq_path = root_knobs_dict['txt_ih_seq_path'] except KeyError: k_ih_seq_path = nuke.String_Knob('txt_ih_seq_path', 'sequence path') nuke.root().addKnob(k_ih_seq_path) try: k_ih_shot = root_knobs_dict['txt_ih_shot'] except KeyError: k_ih_shot = nuke.String_Knob('txt_ih_shot', 'shot') nuke.root().addKnob(k_ih_shot) try: k_ih_shot_path = root_knobs_dict['txt_ih_shot_path'] except KeyError: k_ih_shot_path = nuke.String_Knob('txt_ih_shot_path', 'shot path') nuke.root().addKnob(k_ih_shot_path) k_ih_show.setValue(str_show) k_ih_show_path.setValue(str_show_path) k_ih_seq.setValue(str_seq) k_ih_seq_path.setValue(str_seq_path) k_ih_shot.setValue(str_shot) k_ih_shot_path.setValue(str_shot_path) # remove old favorite directories if they exist nuke_prefs_file = os.path.join(os.path.expanduser("~"), '.nuke', 'FileChooser_Favorites.pref') if os.path.exists(nuke_prefs_file): with open(nuke_prefs_file) as npf: for line in npf: if line.startswith('add_favorite_dir'): line_array = shlex.split(line) fav_name = line_array[1] if fav_name.startswith('SHOW') or fav_name.startswith( 'SEQ') or fav_name.startswith('SHOT'): nuke.removeFavoriteDir(fav_name) # add favorite directories in file browser # TODO: pull these values out of the show config file nuke.addFavoriteDir("SHOW", '[getenv IH_SHOW_ROOT]') if os.path.exists(os.path.join(str_show_root, 'SHARED')): nuke.addFavoriteDir("SHOW/SHARED", os.path.join('[getenv IH_SHOW_ROOT]', 'SHARED')) if os.path.exists(os.path.join(str_show_root, 'ref')): nuke.addFavoriteDir("SHOW/ref", os.path.join('[getenv IH_SHOW_ROOT]', 'ref')) if 'SEQUENCE' in cfg_shot_dir: nuke.addFavoriteDir("SEQ", '[getenv SEQ_PATH]') if os.path.exists(os.path.join(str_seq_path, 'SHARED')): nuke.addFavoriteDir("SEQ/SHARED", os.path.join('[getenv SEQ_PATH]', 'SHARED')) if os.path.exists(os.path.join(str_seq_path, 'ref')): nuke.addFavoriteDir("SEQ/ref", os.path.join('[getenv SEQ_PATH]', 'ref')) nuke.addFavoriteDir("SHOT", '[getenv SHOT_PATH]') # shot directories try: l_nukescript_dir = config.get('shot_structure', 'nukescript_dir').split('{pathsep}') l_plate_dir = config.get('shot_structure', 'plate_dir').split('{pathsep}') l_precomp_dir = config.get('shot_structure', 'precomp_dir').split('{pathsep}') l_rendercomp_dir = config.get('shot_structure', 'rendercomp_dir').split('{pathsep}') l_element_dir = config.get('shot_structure', 'element_dir').split('{pathsep}') l_renderelem_dir = config.get('shot_structure', 'renderelem_dir').split('{pathsep}') l_mograph_dir = config.get('shot_structure', 'mograph_dir').split('{pathsep}') l_ref_dir = config.get('shot_structure', 'ref_dir').split('{pathsep}') l_nukescript_dir.insert(0, r'[getenv SHOT_PATH]') l_plate_dir.insert(0, r'[getenv SHOT_PATH]') l_precomp_dir.insert(0, r'[getenv SHOT_PATH]') l_rendercomp_dir.insert(0, r'[getenv SHOT_PATH]') l_element_dir.insert(0, r'[getenv SHOT_PATH]') l_renderelem_dir.insert(0, r'[getenv SHOT_PATH]') l_mograph_dir.insert(0, r'[getenv SHOT_PATH]') l_ref_dir.insert(0, r'[getenv SHOT_PATH]') log.info( 'Successfully retrieved Shot directory structure from config file.' ) log.info(l_nukescript_dir) log.info(os.path.sep.join(l_nukescript_dir)) nuke.addFavoriteDir("SHOT/nuke", os.path.sep.join(l_nukescript_dir)) nuke.addFavoriteDir("SHOT/plates", os.path.sep.join(l_plate_dir)) nuke.addFavoriteDir("SHOT/precomp", os.path.sep.join(l_precomp_dir)) nuke.addFavoriteDir("SHOT/comp", os.path.sep.join(l_rendercomp_dir)) nuke.addFavoriteDir("SHOT/elements", os.path.sep.join(l_element_dir)) nuke.addFavoriteDir("SHOT/renders", os.path.sep.join(l_renderelem_dir)) nuke.addFavoriteDir("SHOT/mograph", os.path.sep.join(l_mograph_dir)) nuke.addFavoriteDir("SHOT/ref", os.path.sep.join(l_ref_dir)) except Exception as e: log.warning( "Caught exception %s when attempting to extract shot structure from the config file. Reverting to hard-coded shortcut paths." % type(e).__name__) log.warning(traceback.format_exc()) nuke.addFavoriteDir("SHOT/nuke", os.path.join('[getenv SHOT_PATH]', 'nuke')) nuke.addFavoriteDir( "SHOT/plates", os.path.join('[getenv SHOT_PATH]', 'pix', 'plates')) nuke.addFavoriteDir( "SHOT/precomp", os.path.join('[getenv SHOT_PATH]', 'pix', 'precomp')) nuke.addFavoriteDir("SHOT/comp", os.path.join('[getenv SHOT_PATH]', 'pix', 'comp')) nuke.addFavoriteDir( "SHOT/elements", os.path.join('[getenv SHOT_PATH]', 'pix', 'elements')) nuke.addFavoriteDir( "SHOT/renders", os.path.join('[getenv SHOT_PATH]', 'pix', 'renders')) nuke.addFavoriteDir( "SHOT/mograph", os.path.join('[getenv SHOT_PATH]', 'pix', 'mograph')) nuke.addFavoriteDir("SHOT/ref", os.path.join('[getenv SHOT_PATH]', 'ref'))