// =========================================================================== // 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: 2006 // // Description: // Given a list of objects, sort it according to which objects // are controlled by a single cache and which are controlled by // a group cache. Returns a string array with separator string "*" // between groups. // // As an example: // Say the list comes in as: p1, p2, p3, p4, p5, p6 // Objects p1 and p4 are already controlled by a single cacheFile. // Objects p2 and p6 are already controlled by a different cacheFile. // Object p3 is not yet cached. // Object p6 is controlled by a single cacheFile. // // The return would be: p1, p4, *, p2, p6, *, p3, *, p6 // // If none of the objects in the list are cached, they will // be returned as a single list. // global string $gCacheGroupSeparator = "*"; proc int objSharesCache(string $obj, string $otherCaches[]) { string $caches[] = `findExistingCaches($obj)`; for ($cache in $caches) { if (stringArrayContains($cache,$otherCaches)) { return 1; } } return 0; } global proc string[] getObjectsByCacheGroup(string $objs[]) { string $result[]; global string $gCacheGroupSeparator; string $separator = $gCacheGroupSeparator; // will be used to store objs with no cache // string $cacheless[]; int $ii, $jj; int $objCount = size($objs); if ($objCount <= 1) { $result = $objs; return $result; } for ($ii = 0; $ii < $objCount; $ii++) { string $currObj = $objs[$ii]; if (stringArrayContains($currObj, $result)) { continue; } string $caches[] = `findExistingCaches($currObj)`; if (size($caches) == 0) { $cacheless[size($cacheless)] = $currObj; continue; } $result[size($result)] = $currObj; for ($jj = $ii+1; $jj < $objCount; $jj++) { if (objSharesCache($objs[$jj],$caches)) { $result[size($result)] = $objs[$jj]; } } $result[size($result)] = $separator; } if (size($cacheless) == $objCount) { $result = $cacheless; } else { int $resultCount = size($result); if ($resultCount > 0) { if ($result[$resultCount-1] == $separator) { $resultCount--; } } for ($obj in $cacheless) { $result[$resultCount] = $separator; $result[$resultCount+1] = $obj; $resultCount += 2; } } return $result; }