// =========================================================================== // 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: Oct, 2000 // // Procedure Name: // mergeCharacters // // Description: // Merge multiple characters into a single character. If multiple // characters are selected and some of the characters are subcharacters // of another of the characters, the subcharacters will be merged // into the highest level character. If none of the characters are // subcharacters, the merge will be into the last selected character. // // Input Arguments: // none: works on the selection list // // Return Value: // name of the character that the other characters were merged to // proc string[] findParentChar(string $chars[]) // // Given a list of characters, recursively find those which are parents of // other characters in the list. Keep going til you find the most // parent characters of all. // { int $charCount = size($chars); string $parentChar[]; int $ii, $jj; for ($ii = 0; $ii < $charCount; $ii++) { $parentChar[$ii] = ""; for ($jj = 0; $jj < $charCount; $jj++) { if ($ii == $jj) continue; if (`character -isMember $chars[$jj] $chars[$ii]`) { $parentChar[$ii] = $chars[$jj]; break; } } } string $pc; int $sizeCompressed = 0; string $compressedParents[]; for ($ii = 0; $ii < $charCount; $ii++) { if ("" != $parentChar[$ii]) { $compressedParents[$sizeCompressed] = $parentChar[$ii]; $sizeCompressed++; } } // continue searching for parents until one or less is found // if (size($compressedParents) < 2) { return $compressedParents; } else { string $newParents[]; $newParents = findParentChar($compressedParents); if (size($newParents) == 0) { return $compressedParents; } else { return $newParents; } } } global proc string mergeCharacters() // Description: // Merge multiple characters into a single character. If multiple // characters are selected and some of the characters are subcharacters // of another of the characters, the subcharacters will be merged // into the highest level character. If none of the characters are // subcharacters, the merge will be into the last selected character. // { // Check for the proper selection -> two or more characters // string $chars[] = `ls -sl -type character`; int $charCount = size($chars); if ($charCount < 2) { error( (uiRes("m_mergeCharacters.kSelectTheCharsErr")) ); return ""; } // Find the character to merge to (highest character in hierarchy, // or if there are no subcharacters, just use the last selected character) // string $mergeChar; string $parentChars[] = findParentChar($chars); if (size($parentChars)) { $mergeChar = $parentChars[size($parentChars)-1]; } else { $mergeChar = $chars[$charCount-1]; } string $character; for ($character in $chars) { if ($character == $mergeChar) continue; string $mem; string $members[] = `character -q $character`; string $attrs[]; clear $attrs; for ($mem in $members) { if (nodeType($mem) != "character") { $attrs[size($attrs)] = $mem; } } // transfer the attrs to the destination character // character -e -fe $mergeChar $members; // delete the source character // delete $character; } return $mergeChar; }