// =========================================================================== // 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: Jun 20, 1997 // // // // // string[] groupObjectsByName( string $objectList[], string $token ) // // // Given a list of strings, this procedure groups the strings into // lists with the same object. // // // string[] $objectList List of objects to be grouped // string $token Separator at which the object grouping is defined // // // string[] : $objectList, grouped by types separated by $token // // // string $objectList[] = { "curve1.cv[1]", // "curve1.u[0.3]", // "curve3.cv[2]", // "curve4.cv[0]", // "curve1.cv[0]" }; // groupObjectsByName($objectList, "."); // // Result : { "curve1.cv[1] curve1.u[0.3] curve1.cv[0]", // // "curve3.cv[2]", "curve4.cv[0]" } // // // // The token is the string that limits the object name. Changing // // the token gives different results. // // // groupObjectsByName($objectList, "["); // // Result : { "curve1.cv[1] curve1.cv[0]", "curve1.u[0.3]", // // "curve3.cv[2]", "curve4.cv[0]" } // // // // proc int foundObjectInList( string $name, string $listOfNames[] ) // // Description: // This procedure returns true if the given name was found in the // list of names. WARNING: this is a slow algorithm and is not // efficient when dealing with a long list of names. // { int $index = -1; int $foundName = false; int $numNames = size( $listOfNames ); for( $i = 0; $i < $numNames; $i ++ ) { if( $name == $listOfNames[$i] ) { $foundName = true; $index = $i; return $index; } } return $index; } global proc string[] groupObjectsByName( string $objectList[], string $token ) { string $processedNames[]; string $argList[]; int $i; // for each object in objectList, try to group it with previous objects // int $numObjects = size($objectList); for( $i = 0; $i < $numObjects; $i ++ ) { string $objectName[]; $numTokens = `tokenize $objectList[$i] $token $objectName`; if( $numTokens > 0 ) { int $index = foundObjectInList( $objectName[0], $processedNames ); if( $index >= 0 ) { // Concatenate the string // $argList[$index] = $argList[$index] + " "; $argList[$index] = $argList[$index] + $objectList[$i]; } else { // Add this name to the $processedNames // int $processedNamesSize = size( $processedNames ); $processedNames[$processedNamesSize] = $objectName[0]; // start a new arg string // int $argSize = size( $argList ); $argList[$argSize] = $objectList[$i]; } } } return $argList; }