// =========================================================================== // 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. // =========================================================================== // // // Creation Date: 07.Nov.2002 // // Procedure Name: // checkForUnknownNodes // // Description: // Check the scene for unknown nodes before saving the scene. // If unknown nodes are found prompt the user with a dialog asking // if the nodes should be removed. // // Input Arguments: // None. // // Return Value: // int number of unknown nodes removed // proc unlockAndDeleteNode(string $nodeName) { // Delete the unknown node int $isLocked[] = `lockNode -q -lock $nodeName`; if($isLocked[0]){ lockNode -lock false $nodeName; } delete $nodeName; } global proc int checkForUnknownNodes() { int $numUnknownNodes = 0; if (`about -ltVersion`) { string $allUnknownNodes[] = `ls -type unknown -type unknownDag -type unknownTransform`; $numUnknownNodes = size($allUnknownNodes); string $yes = (uiRes("m_checkForUnknownNodes.kYes")); string $no = (uiRes("m_checkForUnknownNodes.kNo")); string $ok = (uiRes("m_checkForUnknownNodes.kOK")); if (0 < $numUnknownNodes) { string $response = $yes; if ($yes == $response) { print (uiRes("m_checkForUnknownNodes.kDletingUnknown")); print $allUnknownNodes; for($unknownNode in $allUnknownNodes) { // Validate if the node still exist, sometimes node deletion triggers other node deletion. if(`objExists $unknownNode`) { if(catchQuiet(`delete $unknownNode`)) { // If the node that we try do delete is in a locked containers we need to unlock that or these containers // in order to be able to delete it. string $parentContainer = $unknownNode; string $nodeToRelock[]; while(true) { $parentContainer = `container -q -findContainer $parentContainer`; $isLocked = (size($parentContainer) > 0) ? `lockNode -q -lock $parentContainer` : {0}; if($isLocked[0]){ $nodeToRelock[size($nodeToRelock)] = $parentContainer; } else { break; } } // Unlock the locked containers found in reverse order int $i = (size( $nodeToRelock ) -1); for( ; $i >= 0; $i-- ) { lockNode -lock false $nodeToRelock[$i]; } unlockAndDeleteNode($unknownNode); // Relock the containers for($lockedContainer in $nodeToRelock) { lockNode -lock true $lockedContainer; } } } } } } } return ($numUnknownNodes); }