// =========================================================================== // 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: 17 April 2007 // // Description: // This is part of a set of methods for changing // a property sheet to point to a new node. // (A way of efficiently re-using existing controls) // This method re-connects a control of undetermined type. // // Input Arguments: // The name of the existing control // The name of the new plug // proc string AEgetAttributeTypeProc(string $type, int $isColor) { string $proc = ""; if($isColor) { $proc = "AEreplaceColor"; } else if( $type == "long" ) { $proc = "AEreplaceInt"; } else if( $type == "bool" ) { $proc = "AEreplaceBool"; } else if($type == "time") { $proc = "AEreplaceTime"; } else if( $type == "enum" ) { $proc = "AEreplaceEnum"; } else if( $type == "float" || $type == "double" || $type == "doubleAngle" ) { $proc = "AEreplaceFloat"; } else if( $type == "matrix" ) { $proc = "AEreplaceMatrix"; } else if( $type == "string" ) { $proc = "AEreplaceString"; } else if( $type == "float3" ) { $proc = "AEreplaceVector"; } else if( $type == "message" ) { $proc = "AEreplaceMessage"; } else { $proc = "AEreplaceOther"; } return $proc; } global proc AEreplaceCompound ( string $controlName, string $plugName, string $changedCommand ) { // Get node name and attr name string $buffer[]; tokenize($plugName, ".", $buffer); string $node = $buffer[0]; string $compoundParent = $buffer[size($buffer) - 1]; // $compoundMultiParent is compound parent attr with [ ] (in case multi) or without [ ] (if not multi) // $compoundParent is compound parent attr ALWAYS WITHOUT [ ] $compoundMultiParent = $compoundParent; int $isMulti = 0; // Is this multi compound? // if so, $plugname looks like this: attrname[n] clear($buffer); tokenize($compoundParent, "[",$buffer); // Yes. multi compound if( size($buffer) >0 ) { $compoundParent = $buffer[0]; $isMulti = 1; } // attributeQuery does NOT take multi attr. // For ex, `attributeQuery -node "myNode" -listChildren "colors[0]"` is error // Instead, use `attributeQuery -node "myNode" -listChildren "colors" // So, we have to use $compoundParent string $childAttrs[] = `attributeQuery -node $node -listChildren $compoundParent`; // No child! // This attr is not compound. // Call AEnewOther instead. int $numChildren = size($childAttrs); if( $numChildren == 0 ) { AEreplaceOther($controlName, $plugName, $changedCommand); return; } string $childType, $childPlug; setUITemplate -pst attributeEditorTemplate; // First, the formLayout label frameLayout -e -l `attributeName -nice $plugName` $controlName; // Get the column layout string $columnLayout[] = `frameLayout -q -childArray $controlName`; setParent $columnLayout[0]; // Get the layout's children string $childrenUI[] = `columnLayout -q -childArray $columnLayout[0]`; // We need to use another pointer to keep track of which UI widget we are pointing to. // In AEnewCompound.mel, we did not construct any widgets for attributes that are hidden. // Therefore, the number of childrenUI and childAttrs will not be the same. // We use childUIPtr to point to the correct widget in $childrenUI. // int $childUIPtr = 0; int $isMultiAttr; string $childAttrName; for($i=0; $i<$numChildren; $i++) { $childAttrName = $childAttrs[$i]; // Skip any hidden attributes. if(`attributeQuery -hidden -node $node $childAttrName`) { continue; } $childPlug = ($node + "." + $compoundMultiParent + "." + $childAttrName); $childType = `getAttr -type $childPlug`; string $childControl = `setParent -query` + "|" + $childrenUI[$childUIPtr]; $isMultiAttr = `attributeQuery -node $node -multi $childAttrName`; if($isMultiAttr && `attributeQuery -node $node -multi $compoundParent`) { AEreplaceOther($childControl, $plugName, $changedCommand); } else if ($isMultiAttr) { if ($childType == "TdataCompound"){ // Sometimes getAttr -type and attributeQuery -attributeType return different // values. // It would return the same value if we did a call of getAttr -type on one // of the multi child. $childType = `attributeQuery -node $node -attributeType $childAttrName`; } int $indices[] = `getAttr -multiIndices $childPlug`; string $proc = AEgetAttributeTypeProc($childType, `attributeQuery -node $node -usedAsColor $childAttrName`); AEreplaceNonNumericMulti( $childControl, $plugName, $childAttrName, $changedCommand, $proc, $indices); } else { string $proc = AEgetAttributeTypeProc($childType, `attributeQuery -node $node -usedAsColor $childAttrName`); string $cc = "\"\""; if ($changedCommand != "") { $cc = ("("+$changedCommand+" \""+$plugName+"\")"); } string $cmd = ( $proc + " \"" + $childControl + "\" \"" + $childPlug + "\" " + $cc); eval($cmd); } // Increment the UI ptr once we successfully handled a non-hidden attribute $childUIPtr ++; } // Multi Compound attr has "Delete" button for each compound. if( $isMulti ) { if( size($childrenUI) > $numChildren ) { // "Delete" button is in a rowLayout setParent $childrenUI[$numChildren]; string $deleteButtonControls[] = `rowLayout -q -childArray $childrenUI[$numChildren]`; symbolButton -e -command ("AEremoveMultiElement " + $plugName) $deleteButtonControls[1]; setParent ..; } } setParent ..; // columnLayout setParent ..; // frameLayout setUITemplate -popTemplate; }