// =========================================================================== // 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: Nov 1998 // // Description: // Delete unused deformers in the scene. // ///////////////////////////////////////////////////////////////////////// global proc int deleteUnusedDeformers() { // Are we being called during an Optimize Scene Size operation? // If so, we need to display progress information. This was done // as a global variable to avoid having to change the signature of // the proc, as that could break many scripts, both internal and // customer-written. // int $showProgress = cleanUp_ShouldReportProgress(); string $deformers[200]; int $numDeleted = 0; // we store them up and don't delete them using a single delete command // since deleting one might cause others to get deleted and the loop // would get messed up // string $nodesToDelete; $deformers = `ls -type geometryFilter`; // do this now (instead of below) so we know how many nodes we will have // to traverse (for progress reporting) // string $intermedObjs[] = `ls -type controlPoint -io`; // initialize progress bar if required // if( $showProgress ) { // we will be traversing the geometryFilter and controlPoint object lists // cleanUp_StartProgress( (size($deformers)+size($intermedObjs)), "Finding unused deformers", 1 ); } int $interrupted = 0; int $i = 0; string $def; for ($def in $deformers) { string $defset[1]; string $members[20]; // update progress and check for interrupt, if required. // if( $showProgress ) { if( cleanUp_SetProgress( $i ) ) { $interrupted = 1; break; } } $defset = `listConnections -type objectSet ($def+".msg")`; if (0 == size($defset)) { $nodesToDelete += ($def +" "); $numDeleted++; } else { $members = `sets -q $defset[0]`; if (0 == size($members)) { $nodesToDelete += ($def+" "); $numDeleted++; } } $i++; } // also delete any intermediate objects that have no output connections // //string $intermedObjs[] = `ls -type controlPoint -io`; // skip this step if the user interrupted the first stage // if( !$interrupted ) { $i = 0; string $obj; for ($obj in $intermedObjs) { // Update progress and check for interrupt, if necessary // if( $showProgress ) { if( cleanUp_SetProgress($i+size($deformers)) ) { $interrupted = 1; break; } } string $outputs[] = `listConnections -s 0 -d 1 -p 1 $obj`; if (size($outputs) == 0) { $nodesToDelete += ($obj+" "); $numDeleted++; } $i++; } } // Finalize progress bar if necessary // if( $showProgress ) { cleanUp_EndProgress(); } // Delete the unused nodes that were found, but only if the user didn't // interrupt the process // if (size($nodesToDelete) && !$interrupted ) { // wrap the delete operation in a progress message, as it can // take several seconds to run on large scenes. // if( $showProgress ) { cleanUp_StartProgress( -1, "Deleting unused deformers", 0 ); } $cmd = ("delete "+$nodesToDelete); evalEcho($cmd); // finalize the progress // if( $showProgress ) { cleanUp_EndProgress(); } return $numDeleted; } else { return 0; } }