def add_fitment(): import os import nuke nuke_main_menu = nuke.menu('Nuke') dayu_main_menu = nuke_main_menu.addMenu('Dayu toolkit') nuke_nodes_menu = nuke.menu('Nodes') dayu_nodes_menu = nuke_nodes_menu.addMenu('Dayu toolkit', icon=NUKE_DEFAULT_ICON) custom_path = os.environ.get('MY_CUSTOM_FITMENT', '') if not custom_path: return try: root_path = Path(custom_path) main_menu_dir = root_path.child(NUKE_MAIN_MENU_DIR) toolbar_menu_dir = root_path.child(NUKE_TOOL_BAR_DIR) views_dir = root_path.child(NUKE_VIEWS_DIR) for root_dir, root_menu in [(main_menu_dir, dayu_main_menu), (toolbar_menu_dir, dayu_nodes_menu)]: if root_dir.isdir(): root_menu.clearMenu() for find_file in root_dir.listdir(): if find_file.isdir(): for match in find_file.walk(filter=file_filter): match_file = MatchFile(match, find_file.parent) match_file.add_to_menu(root_menu) elif file_filter(find_file): match_file = MatchFile(find_file, find_file.parent) match_file.add_to_menu(root_menu) # 加载 views 下的LUT文件 if views_dir.isdir(): for lut_file in views_dir.listdir(file_filter=lut_filter): nuke.ViewerProcess.register(lut_file.stem, nuke.createNode, ("Vectorfield", 'vfield_file %s' % lut_file.replace('\\', '/'))) # 刷新按钮 refresh_command = dayu_nodes_menu.addCommand('refresh', command=add_fitment, tooltip='refresh', index=-1) refresh_command.setIcon(RELOAD_ICON) except Exception as e: traceback.print_exc() return
def add_fitment(): import os import nuke nuke_main_menu = nuke.menu('Nuke') nuke_nodes_menu = nuke.menu('Nodes') custom_path = os.environ.get('MY_CUSTOM_FITMENT', '') if not custom_path: return try: root_path = Path(custom_path).child('nuke') main_menu_dir = root_path.child(NUKE_MAIN_MENU_DIR) toolbar_menu_dir = root_path.child(NUKE_TOOL_BAR_DIR) views_dir = root_path.child(NUKE_VIEWS_DIR) # main_menu 下的文件显示在主菜单上 if main_menu_dir.isdir(): for dir in main_menu_dir.listdir(file_filter=os.path.isdir): parent = nuke_main_menu.addMenu(dir.name) for match in dir.walk(filter=file_filter): match_file = MatchFile(match, dir) match_file.add_to_menu(parent) # nodes 下的文件生成在 toolbar 上 if toolbar_menu_dir.isdir(): for dir in toolbar_menu_dir.listdir(file_filter=os.path.isdir): parent = nuke_nodes_menu.addMenu(dir.name, find_icon(dir)) for match in dir.walk(filter=file_filter): match_file = MatchFile(match, dir) match_file.add_to_menu(parent) # 加载 views 下的LUT文件 if views_dir.isdir(): for file in views_dir.listdir(file_filter=lut_filter): nuke.ViewerProcess.register(file.stem, nuke.createNode, ("Vectorfield", 'vfield_file %s' % file.replace('\\', '/'))) refresh_menu = nuke_nodes_menu.addMenu('refresh', RELOAD_ICON) refresh_command = refresh_menu.addCommand('refresh', command=add_fitment, tooltip='refresh') refresh_command.setIcon(RELOAD_ICON) except Exception as e: traceback.print_exc() return
def add_to_menu(self, parent_root): import nuke command = self._command() sub_level = self._menu_level() tooltip = self.file_path.stem nuke.pluginAppendPath(self.file_path.parent) parent_root.addCommand(sub_level, command=command, tooltip=tooltip) # 从根部层级 一层层的查找对应menu的icon parent_menu = parent_root icon_path = Path(self.pre_path) for sub in sub_level.split('/'): icon_path = icon_path.child(sub) parent_menu = parent_menu.menu(sub) parent_menu.setIcon(find_icon(icon_path)) parent_menu.setShortcut(find_hotkey(icon_path))