Files
Nexus/plug-ins/ARTv2/clean_scene_contexts.py
2025-12-07 23:00:40 +08:00

72 lines
1.7 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Clean ARTv2 tool contexts from Maya scene
Use this script before or after opening old ARTv2 scenes
"""
from __future__ import print_function
import maya.cmds as cmds
def clean_artv2_contexts():
"""
Remove all ARTv2 tool contexts and reset to default tool
"""
print("=" * 60)
print("Cleaning ARTv2 Tool Contexts")
print("=" * 60)
# Get all UI contexts
try:
contexts = cmds.lsUI(contexts=True) or []
except:
contexts = []
# Find ARTv2 related contexts
art_contexts = []
for ctx in contexts:
if 'art' in ctx.lower() or 'ART' in ctx.upper():
art_contexts.append(ctx)
print(f"\nFound {len(art_contexts)} ARTv2 contexts:")
# Delete ARTv2 contexts
deleted = 0
for ctx in art_contexts:
try:
if cmds.contextInfo(ctx, exists=True):
cmds.deleteUI(ctx)
print(f" ✓ Deleted: {ctx}")
deleted += 1
except Exception as e:
print(f" ✗ Failed to delete {ctx}: {e}")
# Reset to default tool
try:
cmds.setToolTo('selectSuperContext')
print("\n✓ Reset to default selection tool")
except:
try:
cmds.selectMode(object=True)
print("\n✓ Reset to object selection mode")
except Exception as e:
print(f"\n✗ Failed to reset tool: {e}")
print(f"\nCleaned up {deleted} contexts")
print("=" * 60)
return deleted
def clean_on_scene_open(*args):
"""
Callback function to clean contexts when scene is opened
"""
clean_artv2_contexts()
# Run immediately when imported
if __name__ == "__main__":
clean_artv2_contexts()