118 lines
3.9 KiB
Python
118 lines
3.9 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Shelf Reload Script
|
|
Run this script in Maya Script Editor to reload NexusLauncher shelf
|
|
"""
|
|
import maya.cmds as cmds
|
|
import maya.mel as mel
|
|
|
|
|
|
def reload_shelf():
|
|
"""Reload NexusLauncher shelf"""
|
|
print("\n" + "=" * 60)
|
|
print("Reloading NexusLauncher Shelf")
|
|
print("=" * 60)
|
|
|
|
# 1. Delete old shelf
|
|
if cmds.shelfLayout('NexusLauncher', exists=True):
|
|
old_buttons = cmds.shelfLayout('NexusLauncher', query=True, childArray=True) or []
|
|
print(f"[1/4] Deleting old shelf (had {len(old_buttons)} button(s))...")
|
|
cmds.deleteUI('NexusLauncher', layout=True)
|
|
print(" ✓ Old shelf deleted")
|
|
else:
|
|
print("[1/4] No existing shelf found")
|
|
|
|
# 2. Reload shelf (using new method)
|
|
import os
|
|
shelf_paths = os.environ.get('MAYA_SHELF_PATH', '')
|
|
|
|
# Find shelf file
|
|
shelf_file_found = None
|
|
if shelf_paths:
|
|
path_separator = ';' if os.name == 'nt' else ':'
|
|
for shelf_path in shelf_paths.split(path_separator):
|
|
shelf_file = os.path.join(shelf_path.strip(), "shelf_NexusLauncher.mel")
|
|
if os.path.exists(shelf_file):
|
|
shelf_file_found = shelf_file.replace("\\", "/")
|
|
break
|
|
|
|
if not shelf_file_found:
|
|
print("[2/4] ✗ Could not find shelf_NexusLauncher.mel in MAYA_SHELF_PATH")
|
|
return False
|
|
|
|
print(f"[2/4] Loading shelf from: {shelf_file_found}")
|
|
|
|
try:
|
|
# Disable auto-save
|
|
mel.eval('optionVar -intValue "saveLastLoadedShelf" 0;')
|
|
|
|
# Create shelf layout
|
|
mel.eval('''
|
|
global string $gShelfTopLevel;
|
|
setParent $gShelfTopLevel;
|
|
shelfLayout -cellWidth 35 -cellHeight 34 NexusLauncher;
|
|
''')
|
|
|
|
# Set parent and execute shelf script
|
|
mel.eval('setParent NexusLauncher;')
|
|
mel.eval(f'source "{shelf_file_found}";')
|
|
mel.eval('shelf_NexusLauncher();')
|
|
|
|
print(" ✓ Shelf loaded (temporary, won't be saved)")
|
|
except Exception as e:
|
|
print(f" ✗ Failed to load shelf: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
# 3. Verify shelf
|
|
if cmds.shelfLayout('NexusLauncher', exists=True):
|
|
print("[3/4] Verifying shelf...")
|
|
buttons = cmds.shelfLayout('NexusLauncher', query=True, childArray=True) or []
|
|
|
|
if buttons:
|
|
print(f" ✓ Shelf has {len(buttons)} button(s)")
|
|
|
|
# Display button details
|
|
for i, btn in enumerate(buttons, 1):
|
|
try:
|
|
label = cmds.shelfButton(btn, query=True, label=True)
|
|
annotation = cmds.shelfButton(btn, query=True, annotation=True)
|
|
source_type = cmds.shelfButton(btn, query=True, sourceType=True)
|
|
print(f" Button {i}: {label} ({source_type})")
|
|
print(f" {annotation}")
|
|
except Exception as e:
|
|
print(f" ✗ Error querying button {i}: {e}")
|
|
else:
|
|
print(" ⚠ Warning: Shelf exists but has no buttons!")
|
|
return False
|
|
else:
|
|
print("[3/4] ✗ Shelf not found after loading!")
|
|
return False
|
|
|
|
# 4. Test button command
|
|
print("[4/4] Testing button command...")
|
|
try:
|
|
import nexus_test
|
|
print(" ✓ nexus_test module imported")
|
|
|
|
# Run test
|
|
print(" Running test...")
|
|
nexus_test.run_test()
|
|
print(" ✓ Test executed successfully!")
|
|
except Exception as e:
|
|
print(f" ✗ Test failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
print("=" * 60)
|
|
print("✓ Shelf reload complete!")
|
|
print("=" * 60 + "\n")
|
|
return True
|
|
|
|
|
|
if __name__ == '__main__':
|
|
reload_shelf()
|