// =========================================================================== // 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: 29 March 2005 // // // // // // string addPrefixToName(string $prefix, string $nodeName) // // // Adds $prefix to the beginning of $nodeName. This script will // handle DAG paths by adding the $prefix to the beginning of // every node name in the DAG path. // // NOTE: This script will not actually rename $nodeName, it just // generates a string. // // // string $prefix The string to add. // string $nodeName The node name to be prefixed. // // // string : The prefixed node name. // // // addPrefixToName( "shaders:", "blinn1SG" ); // // Result: shaders:blinn1SG // addPrefixToName( "skel:", "joint1|joint2|joint3" ); // // Result: skel:joint1|skel:joint2|skel:joint3 // addPrefixToName( "invalid:", "" ); // // Result: // // // global proc string addPrefixToName(string $prefix, string $nodeName) { string $result; if ( "" == $nodeName ) { return ""; } int $hasLeadingBar = ("|" == `substring $nodeName 1 1`); string $path[]; int $pathLength = `tokenize $nodeName "|" $path`; if ( $pathLength > 0 ) { // Add $prefix to all names in $nodeName. // int $i = 0; for ( $i = 0; $i < $pathLength; $i++ ) { $path[$i] = ($prefix + $path[$i]); } // Build $result from the, now prefixed, elements of $nodeName // $result = ""; if ( $hasLeadingBar ) { $result = "|"; } $result += $path[0]; for ( $i = 1; $i < $pathLength; $i++ ) { $result += "|" + $path[$i]; } } return $result; }