// =========================================================================== // 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 stripPrefixFromName(string $prefix, string $nodeName) // // // Strips $prefix from the beginning of $nodeName. This script will // handle DAG paths by stripping the $prefix from 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 strip. // string $nodeName The node name to be stripped. // // // string : The stripped node name. // // // stripPrefixFromName( "shaders:", "shaders:blinn1SG" ); // // Result: blinn1SG // stripPrefixFromName( "skel:", "skel:joint1|skel:joint2|skel:joint3" ); // // Result: joint1|joint2|joint3 // stripPrefixFromName( "two:", "one:two:myNode" ); // // Result: one:two:myNode // // // global proc string stripPrefixFromName(string $prefix, string $nodeName) { string $result; if ( "" == $nodeName ) { return ""; } int $prefixLength = `size( $prefix )`; int $hasLeadingBar = ("|" == `substring $nodeName 1 1`); string $path[]; int $pathLength = `tokenize $nodeName "|" $path`; if ( $pathLength > 0 ) { // Strip $prefix from all names in path. // int $i = 0; for ( $i = 0; $i < $pathLength; $i++ ) { if ( startsWith( $path[$i], $prefix ) ) { int $elementLength = `size $path[$i]`; $path[$i] = substring( $path[$i], $prefixLength + 1, $elementLength ); } } // Build $result from the, now stripped, elements of $nodeName // $result = ""; if ( $hasLeadingBar ) { $result = "|"; } $result += $path[0]; for ( $i = 1; $i < $pathLength; $i++ ) { $result += "|" + $path[$i]; } } return $result; }