// =========================================================================== // 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. // =========================================================================== global proc removeDuplicatedShadingNetworksForSelection() { string $selectedNodes[] = `ls -selection`; select -clear; for ($node in $selectedNodes) select -add -hierarchy $node; string $allUnder[] = `ls -selection`; string $connections[] = `listConnections $allUnder`; string $shadingNetworks[] = stringArrayRemoveDuplicates( `ls -type shadingEngine $connections`); for ( $i = 0; $i < `size $shadingNetworks`; $i++ ) { if ( !`objExists $shadingNetworks[ $i ]` ) continue; for ( $j = $i + 1; $j < `size $shadingNetworks`; $j++ ) { if ( !`objExists $shadingNetworks[ $j ]` ) continue; $duplicateFound = 0; string $comparison = `shadingNetworkCompare $shadingNetworks[$i] $shadingNetworks[$j]`; if ( `shadingNetworkCompare -q -equivalent $comparison` ) { string $network1[] = `shadingNetworkCompare -q -network1 $comparison`; // If the networks are equivalent then assign all // the geometry connected to the first shading group to // the next one; string $geometries[] = `sets -query $shadingNetworks[ $i ]`; if ( size( $geometries ) > 0 ) { for ($geometry in $geometries) { if (`stringArrayContains $geometry $allUnder`) { // sets can return invalid geometry, so catch it catchQuiet(`sets -edit -forceElement $shadingNetworks[$j] $geometry` ); } } } $duplicateFound = 1; } shadingNetworkCompare -delete $comparison; if ( $duplicateFound ) { // If a duplicate was found move on to the next shadingEngine break; } } } }