// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // Description : Script to prepare a scene so that a scene with some types // of spurrious light linker nodes may be cleaned up by running // the script, saving the scene, re-opening the scene (which // will trigger the actual clean-up) and re-saving the scene. // // Warning : This is an example script, use at your own risk. // // Example: // Suppose you have a scene that has a number of light linker nodes, // and that Maya refuses to clean them up. One possibility is that these nodes // are not linked to the lightList (e.g., they were created in batch mode in a // Maya 4.0 or before), so Maya doesn't know that it has to clean them up. You // could use this script as follows to get Maya to clean up such spurrious // light linker nodes: // // o Open your scene // o Source this script and run prepareForLightLinkerCleanup // o Save your scene // o Re-open your scene (To get Maya to clean up the spurrious light linkers) // o Save your scene again. // // From this point on, the spurrious light linker nodes should be gone. // Depending on the the number of light linkers to clean up, the Re-open step // could take a long time, but will only have to be done once. // // prepareForLightLinkerCleanup. // // Cleans up a file by going through the list of light linkers, and linking // them to the lightList if that hasn't already been done. // global proc prepareForLightLinkerCleanup() { // First, get the lightList // string $lightLists[] = `ls -type lightList`; string $lightList; if( size($lightLists) == 0 ){ // Create one, if necessary // warning( (uiRes("m_prepareForLightLinkerCleanup.kNoLight")) ); $lightList = `createNode -type lightList`; } else { $lightList = $lightLists[0]; if( size($lightLists) > 1 ){ string $msg=(uiRes("m_prepareForLightLinkerCleanup.kMultipleLight")); warning(`format -stringArg $lightList $msg` ); } } // Now get the light linkers // string $lightLinkers[] = `ls -type lightLinker`; $numLightLinkers = size($lightLinkers); $index = 0; while( $index < $numLightLinkers ){ string $lightLinker = $lightLinkers[$index]; // Check to see if this light linker is already connected to the // light list. // string $dstPlugs[] = `connectionInfo -dfs ($lightLinker + ".msg")`; int $addLink = true; $numPlugs = size($dstPlugs); $plugIndex = 0; while( $plugIndex < $numPlugs ){ if( plugNode( $dstPlugs[0]) == $lightList ){ // Found one, we don't need to add a link; bail out. // $addLink = false; break; } $plugIndex++; } if( $addLink ){ // Connect this light linker to the light list // connectAttr -na ($lightLinker + ".msg") ($lightList + ".ln"); } $index++; } }