#!/usr/bin/env python # -*- coding: utf-8 -*- """ Nexus Shelf Reload Script Use this script to reload Nexus shelves without restarting Maya """ import maya.cmds as cmds import maya.mel as mel import os SHELF_NAMES = ["Nexus_Modeling", "Nexus_Rigging", "Nexus_Animation"] def reload_nexus_shelves(): """Reload all Nexus shelves""" print("=" * 60) print("[Nexus] Reloading Nexus shelves...") print("=" * 60) # Get shelf path shelf_paths = os.environ.get('MAYA_SHELF_PATH', '') if not shelf_paths: print("[Nexus] MAYA_SHELF_PATH not set") try: script_dir = os.path.dirname(os.path.abspath(__file__)) shelf_paths = os.path.join(script_dir, "shelves") print(f"[Nexus] Using script directory: {shelf_paths}") except: print("[Nexus] Could not determine shelf path") return path_separator = ';' if os.name == 'nt' else ':' shelf_path_list = shelf_paths.split(path_separator) for shelf_name in SHELF_NAMES: # Find shelf file shelf_file_found = None for shelf_path in shelf_path_list: shelf_path = shelf_path.strip() if not shelf_path: continue shelf_file = os.path.join(shelf_path, f"shelf_{shelf_name}.mel") shelf_file = shelf_file.replace("\\", "/") if os.path.exists(shelf_file): shelf_file_found = shelf_file break if not shelf_file_found: print(f"[Nexus] Could not find shelf_{shelf_name}.mel") continue # Delete old shelf if exists if cmds.shelfLayout(shelf_name, exists=True): print(f"[Nexus] Deleting old shelf: {shelf_name}") try: cmds.deleteUI(shelf_name, layout=True) except Exception as e: print(f"[Nexus] Warning: Could not delete old shelf: {e}") # Load shelf using proper MEL method print(f"[Nexus] Loading shelf: {shelf_name}") try: # Disable auto-save mel.eval('optionVar -intValue "saveLastLoadedShelf" 0;') # Create shelf layout mel.eval(f''' global string $gShelfTopLevel; if (`shelfLayout -exists {shelf_name}`) {{ deleteUI -layout {shelf_name}; }} setParent $gShelfTopLevel; shelfLayout -cellWidth 35 -cellHeight 34 {shelf_name}; ''') print(f"[Nexus] ✓ Created shelf layout: {shelf_name}") # Set parent and execute shelf script mel.eval(f'setParent {shelf_name};') mel.eval(f'source "{shelf_file_found}";') mel.eval(f'shelf_{shelf_name}();') print(f"[Nexus] ✓ Executed shelf script: shelf_{shelf_name}()") # Verify shelf if cmds.shelfLayout(shelf_name, exists=True): buttons = cmds.shelfLayout(shelf_name, query=True, childArray=True) or [] if buttons: print(f"[Nexus] ✓ Shelf loaded with {len(buttons)} button(s): {shelf_name}") else: print(f"[Nexus] ⚠ Shelf created but no buttons: {shelf_name}") # Remove auto-saved config try: maya_version = cmds.about(version=True).split()[0] maya_app_dir = os.environ.get('MAYA_APP_DIR', '') if maya_app_dir: shelf_config = os.path.join(maya_app_dir, maya_version, "prefs", "shelves", f"shelf_{shelf_name}.mel") if os.path.exists(shelf_config): os.remove(shelf_config) print(f"[Nexus] ✓ Removed auto-saved config: {shelf_name}") except Exception as e: print(f"[Nexus] Warning: {e}") else: print(f"[Nexus] ✗ Shelf layout not created: {shelf_name}") except Exception as e: print(f"[Nexus] Error loading shelf {shelf_name}: {e}") import traceback traceback.print_exc() continue print("=" * 60) print("[Nexus] Shelf reload complete!") print("=" * 60) if __name__ == "__main__": reload_nexus_shelves()