// =========================================================================== // 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: 15 April 1997 // // Description: // This procedure adds property sheet controls for // a new enumerated attribute. This is for internal // use only. // // Input Arguments: // The name of the plug for the attribute // The name of the attribute // The list of enumerated items (strings) // // Return Value: // The name of the newly-created control. // // This procedure returns item list of enum attr node.enumAttr // The returned list contais integer value and string value of each enum item. // For ex, {0, None, 1, Linear, 5, Smooth, ...} proc string[] getEnumItems(string $node, string $enumAttr) { string $result[], $item[], $buffer[]; int $enumValue = 0, $i; // Get raw item list. // $enum will look like: {string=value:string=value:...} // If the enum item uses default value, "=value" is omitted. string $enum[] = `attributeQuery -node $node -listEnum $enumAttr`; // Tokenize by ":" to separate each item tokenize($enum[0], ":", $buffer); for($i = 0 ; $i < size($buffer); $i++) { // Tokenize by "=" to separate integer value from string value clear($item); tokenize($buffer[$i], "=", $item); // If an integer value is specified: if( size($item) > 1 ) { $enumValue = $item[1]; } // Store to result $result[$i*2] = $enumValue; $result[$i*2+1] = $item[0]; // Advance $enumValue $enumValue ++; } return $result; } global proc string AEnewEnum( string $plugName, string $attrName, string $changedCommand, string $enumItems[]) { string $createdControl; string $cmd = ("attrEnumOptionMenuGrp -at \"" + $plugName + "\""); int $i; for ($i = 0; $i < size($enumItems); $i+=2) { $cmd += (" -enumeratedItem " + $enumItems[$i] + " \"" + $enumItems[$i+1]) + "\""; } $createdControl = `eval $cmd`; attrEnumOptionMenuGrp -e -l $attrName $createdControl; if ( $changedCommand != "" ) { string $buffer[]; tokenize($plugName,".",$buffer); string $cmd = $changedCommand + " \"" + $buffer[0] + "\""; scriptJob -p $createdControl -rp -ac $plugName $cmd; } return $createdControl; } // Description: // This procedure allows us to have uniform arguments // in all the "AENew..." functions. // This function will get the enum items and call the // AEnewEnum. // // Input Arguments: // The name of the plug for the attribute // The name of the attribute // The changed command to use // // Return Value: // The name of the newly-created control. // global proc string AEnewEnumWithoutItems( string $plugName, string $attrName, string $changedCommand) { string $retVal; string $buffer[]; tokenize($plugName, ".",$buffer); int $bufferSize = `size($buffer)`; if( $bufferSize > 1 ) { string $node = $buffer[0]; string $childName = $buffer[$bufferSize-1]; tokenize($childName, "[",$buffer); $bufferSize = `size($buffer)`; if( $bufferSize > 1 ) { $childName = $buffer[0]; } string $enumItems[]; $enumItems = getEnumItems($node, $childName ); $retVal = AEnewEnum($plugName, $attrName, $changedCommand, $enumItems); } return $retVal; }