// =========================================================================== // 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. // =========================================================================== // // Procedure Name: // AEassemblyReferenceTempate // // Description Name; // Creates the attribute editor controls for the assembly reference node. // // Input Value: // nodeName // // Output Value: // None // // First creation of the assembly definition template for an assemblyReference node. global proc AEassRefAssemblyDefinitionNew(string $attrName) { string $defaultRep = (uiRes("m_AEassemblyReferenceTemplate.kDefaultRep")); rowLayout -numberOfColumns 3 -columnAttach 2 "left" 0 -adjustableColumn 2; text -label (uiRes("m_AEassemblyReferenceTemplate.kAEassRefassDefName")); textField assRefDefAttrNameValue; iconTextButton -i1 "navButtonBrowse.png" assRefBrowseAssDefPath; setParent ..; rowLayout -numberOfColumns 1 -columnAttach 1 "left" 148; iconTextButton -annotation (uiRes("m_AEassemblyReferenceTemplate.kAEassRefReloadAssDef")) -i1 "refresh.png" assRefRefreshassDef; setParent ..; AEassRefAssemblyDefinitionReplace($attrName); } // Update and replace the assembly definition components. global proc AEassRefAssemblyDefinitionReplace(string $attrName) { string $nodeName = `plugNode $attrName`; connectControl -fileName assRefDefAttrNameValue $attrName; // We're trying to prevent users from making edits to the nested assembly reference assembly // definition attribute, because it currently doesn't work. int $isTopLevel = `python("getOpenMayaAssemblyNode('"+$nodeName+"').isTopLevel()")`; if($isTopLevel) { //If it is top-level, whether it is editable is controlled by the lock status. textField -edit -changeCommand ("select -r \"" + $nodeName + "\"") assRefDefAttrNameValue; } else { textField -edit -changeCommand ("select -r \"" + $nodeName + "\"") -editable false assRefDefAttrNameValue; } iconTextButton -edit -command ("assemblyReferencePostCreateUIProc \""+$nodeName+"\"") -enable $isTopLevel assRefBrowseAssDefPath; iconTextButton -edit -command ("AEassRefReloadDef \""+$attrName+"\"") assRefRefreshassDef; } // Reload the assembly definition. global proc AEassRefReloadDef(string $attrName) { // Set the active representation to none string $nodeName = `plugNode $attrName`; assembly -edit -active "" $nodeName; // Call the assembly reference postLoad python("getOpenMayaAssemblyNode('"+$nodeName+"').postLoad()"); // re-select the assembly reference node to stay in the attribute editor. select -r `plugNode $attrName`; } // First creation of the assembly representation template for an assemblyReference node. global proc AEassRefAssemblyRepresentationsNew(string $attrName) { rowLayout -numberOfColumns 2; text -label (uiRes("m_AEassemblyReferenceTemplate.kAEassRefActiveRepresentation")) -align "right"; string $assRefActiveRepMenu = `optionMenu -annotation (uiRes("m_AEassemblyReferenceTemplate.kAEassRefSelectActiveRep")) -label "" -width 200 assRefActiveRepMenu`; setParent ..; text -label ""; rowLayout -numberOfColumns 2 -adjustableColumn 2 -rowAttach 1 "top" 0; text -label (uiRes("m_AEassemblyReferenceTemplate.kAEassRefRepresentationList")) -height 20 -align "right"; textScrollList -h 130 -allowMultiSelection false assRefScrollListRepLabel; setParent ..; frameLayout -label (uiRes("m_AEassemblyReferenceTemplate.kAEassRefRepAttributes")) -collapse false; columnLayout -adjustableColumn 1; textFieldGrp -label (uiRes("m_AEassemblyReferenceTemplate.kAEassRefRepAttrName")) -editable false assRefRepAttrNameValue; textFieldGrp -label (uiRes("m_AEassemblyReferenceTemplate.kAEassRefRepAttrData")) -editable false assRefRepAttrDataValue; textFieldGrp -label (uiRes("m_AEassemblyReferenceTemplate.kAEassRefRepAttrLabel")) -editable false assRefRepAttrLabelValue; textFieldGrp -label (uiRes("m_AEassemblyReferenceTemplate.kAEassRefRepAttrType")) -editable false assRefRepAttrTypeValue; rowLayout -numberOfColumns 1 -columnAttach 1 "left" 148; iconTextButton -annotation (uiRes("m_AEassemblyReferenceTemplate.kAEassRefReloadRep")) -i1 "refresh.png" assRefRefreshRep; setParent ..; setParent ..; setParent ..; AEassRefAssemblyRepresentationsReplaceImp($assRefActiveRepMenu, $attrName); } // Update and replace the assembly representation components. global proc AEassRefAssemblyRepresentationsReplace(string $attrName) { // Find the menu under the current parent. This will change depending // on whether we're in Hypershade's property editor, or in the // attribute editor. string $assRefActiveRepMenu = `control -q -fullPathName assRefActiveRepMenu`; // Call the engine method. AEassRefAssemblyRepresentationsReplaceImp($assRefActiveRepMenu, $attrName); } // Update and replace the assembly representation components. global proc AEassRefAssemblyRepresentationsReplaceImp( string $assRefActiveRepMenu, string $attrName ) { string $nodeName = `plugNode $attrName`; optionMenu -edit -changeCommand ("AEassRefChangeActiveMenuRep " + $assRefActiveRepMenu + " " + $attrName) $assRefActiveRepMenu; textScrollList -edit -selectCommand ("AEassRefShowAttrInfo \"" + $attrName + "\"" ) assRefScrollListRepLabel; iconTextButton -edit -command ("AEassRefReloadActiveRep \""+$nodeName+"\"") assRefRefreshRep; AEassRefFillMenu($assRefActiveRepMenu, $attrName); AEassRefFillScrollListLabel($attrName); } // Change the active representation by the assRefActiveRepMenu selection. global proc AEassRefChangeActiveMenuRep( string $assRefActiveRepMenu, string $attrName ) { // The IPR sessions don't support drastic representation changes // interactively. So we must stop the IPR session before changing // the representation. Ideally, we would also re-start it after // but shutting down and restarting the renderers so fast is currently // causing some non-trivial race conditions. if (isRunningIpr()) { stopIprRendering ""; } int $menuIndex = `optionMenu -query -select $assRefActiveRepMenu`; string $nodeName = `plugNode $attrName`; if($menuIndex != `optionMenu -query -numberOfItems $assRefActiveRepMenu`) { string $repName = `getAttr ($attrName+"[" + ($menuIndex-1) + "].repName")`; if(catch(`assembly -edit -active $repName $nodeName`)){ // If the file to activate is not found, no need to re-select the assembly definition. // Only refresh the representation list. AEassRefFillMenu($assRefActiveRepMenu, $attrName); AEassRefFillScrollListLabel($attrName); }else{ // Re-select the assembly definition node to stay in the attribute editor, which will also refresh everything. select -r $nodeName; } } else { if(catch(`assembly -edit -active "" $nodeName`)){ // Set back the active representation item in the scroll list AEassRefFillMenu($assRefActiveRepMenu, $attrName); } else { AEassRefFillScrollListLabel($attrName); } } } // Reload the representation, set to active if it was not. global proc AEassRefReloadActiveRep(string $nodeName) { string $repName = `textFieldGrp -query -text assRefRepAttrNameValue`; // Activate none assembly -edit -active "" $nodeName; // Activate the selected representation if(!catch(`assembly -edit -active $repName $nodeName`)){ // re-select the assembly definition node to stay in the attribute editor. select -r $nodeName; } } // Fill the option menu items. global proc AEassRefFillMenu(string $menuName, string $attrName) { string $nodeName = `plugNode $attrName`; string $menuItems[] = `optionMenu -query -itemListLong $menuName`; string $representations[] = `assembly -query -listRepresentations $nodeName`; string $menuItemActiveLabel = (uiRes("m_AEassemblyReferenceTemplate.kAEassRefMenuActiveLabel")); string $menuItemNoneLabel = (uiRes("m_AEassemblyReferenceTemplate.kAEassRefMenuNoneLabel")); string $oldMenuParent = `setParent -query -menu`; if ($oldMenuParent != $menuName) { setParent -menu $menuName; } // remove old menu items if (size($menuItems) > 0) { string $deleteCommand = "deleteUI"; for ($menuItem in $menuItems){ $deleteCommand += (" " + $menuItem); } eval($deleteCommand); } // fill menu items int $nbRep = `getAttr -size $attrName`; for ($i = 0; $i < $nbRep; $i++) { menuItem -label `getAttr ($attrName+"[" + $i + "].repLabel")`; } // Add item 'None' as the last item in the menu list menuItem -label $menuItemNoneLabel; string $buffer[]; int $numTokens = tokenize($menuName, "|", $buffer); if($buffer[$numTokens-1] == "assRefActiveRepMenu") { if ($nbRep > 0) { string $activePath = `assembly -query -active $nodeName`; if (size($activePath) > 0) { // Since we can have duplicated labels. // Select the scroll list item by index by the position of the representation path in the list. //1-based int $itemCnt = 1; string $repName; for ($repName in $representations) { if($repName == $activePath){ break; } $itemCnt++; } optionMenu -edit -enable true -select $itemCnt $menuName; } else { optionMenu -edit -enable true -value $menuItemNoneLabel $menuName; } } else { optionMenu -edit -enable false -value $menuItemNoneLabel $menuName; } } if ($oldMenuParent != $menuName) { setParent -menu $oldMenuParent; } } // Fill the representation label scroll list. global proc AEassRefFillScrollListLabel(string $attrName) { string $nodeName = `plugNode $attrName`; string $listItems[] = `textScrollList -query -allItems assRefScrollListRepLabel`; int $nbRep = `getAttr -size $attrName`; // remove old list items if (size($listItems) > 0){ textScrollList -edit -removeAll assRefScrollListRepLabel; } if($nbRep > 0) { // fill scroll list items for ($i = 0; $i < $nbRep; $i++){ textScrollList -edit -append `getAttr ($attrName+"[" + $i + "].repLabel")` assRefScrollListRepLabel; } int $selectIndex = 1; string $repActive = `assembly -query -active $nodeName`; if(size($repActive) > 0) { // For the active representation selected in the scroll list, // we validate the label and name in case we have duplicated labels. string $repActiveLabel = `assembly -query -repLabel $repActive $nodeName`; string $items[] = `textScrollList -query -allItems assRefScrollListRepLabel`; int $itemCnt = 0; for($item in $items) { if($item == $repActiveLabel) { if($repActive == `getAttr ($attrName+"[" + $itemCnt + "].repName")`) { $selectIndex = $itemCnt+1; textScrollList -edit -lineFont $selectIndex "boldLabelFont" assRefScrollListRepLabel; break; } } $itemCnt++; } } textScrollList -edit -selectIndexedItem $selectIndex assRefScrollListRepLabel; AEassRefShowAttrInfo($attrName); } else { // disable and clean representation attributes component if the representation list is empty. textFieldGrp -edit -text "" assRefRepAttrNameValue; textFieldGrp -edit -text "" assRefRepAttrDataValue; textFieldGrp -edit -text "" assRefRepAttrLabelValue; textFieldGrp -edit -text "" assRefRepAttrTypeValue; iconTextButton -edit -enable false assRefRefreshRep; } } // Show the representation attributes. global proc AEassRefShowAttrInfo(string $attrName) { int $selectedIndex[] = `textScrollList -query -selectIndexedItem assRefScrollListRepLabel`; int $nbItems = `textScrollList -query -numberOfItems assRefScrollListRepLabel`; if($nbItems > 0 && $selectedIndex[0] > 0) { string $repName = `getAttr ($attrName+"[" + ($selectedIndex[0] - 1) + "].repName")`; textFieldGrp -edit -text $repName assRefRepAttrNameValue; textFieldGrp -edit -text `getAttr ($attrName+"[" + ($selectedIndex[0] - 1) + "].repData")` assRefRepAttrDataValue; textFieldGrp -edit -text `getAttr ($attrName+"[" + ($selectedIndex[0] - 1) + "].repLabel")` assRefRepAttrLabelValue; textFieldGrp -edit -text `getAttr ($attrName+"[" + ($selectedIndex[0] - 1) + "].repType")` assRefRepAttrTypeValue; string $nodeName = `plugNode $attrName`; string $repActive = `assembly -query -active $nodeName`; iconTextButton -edit -enable ($repName == $repActive) assRefRefreshRep; } } global proc AEassemblyReferenceTemplate(string $nodeName) { python( "import maya.OpenMaya as OpenMaya\n" + "import maya.app.general.editUtils as editUtils" ); python( "def getOpenMayaAssemblyNode(refNodeName):\n" + " assemblyNode = editUtils.makeDependNode(refNodeName)\n" + " assemblyFn = OpenMaya.MFnAssembly(assemblyNode)\n" + " return assemblyFn" ); editorTemplate -beginScrollLayout; AEtransformMain $nodeName; editorTemplate -beginLayout (uiRes("m_AEassemblyReferenceTemplate.kAEassRefAssemblyDef")) -collapse false; editorTemplate -callCustom "AEassRefAssemblyDefinitionNew" "AEassRefAssemblyDefinitionReplace" "definition"; editorTemplate -callCustom "AEassemblyNamespaceNew" "AEassemblyNamespaceReplace" "repNamespace"; editorTemplate -endLayout; editorTemplate -beginLayout (uiRes("m_AEassemblyReferenceTemplate.kAEassRefAssemblyRep")) -collapse false; editorTemplate -callCustom "AEassRefAssemblyRepresentationsNew" "AEassRefAssemblyRepresentationsReplace" "representations"; editorTemplate -endLayout; AEtransformNoScroll $nodeName; editorTemplate -addExtraControls; // suppresses attributes editorTemplate -suppress "initialRep"; editorTemplate -suppress "assemblyEdits"; editorTemplate -suppress "blackBox"; editorTemplate -suppress "rmbCommand"; editorTemplate -suppress "templateName"; editorTemplate -suppress "templatePath"; editorTemplate -suppress "viewName"; editorTemplate -suppress "iconName"; editorTemplate -suppress "viewMode"; editorTemplate -suppress "templateVersion"; editorTemplate -suppress "uiTreatment"; editorTemplate -suppress "customTreatment"; editorTemplate -suppress "creator"; editorTemplate -suppress "creationDate"; editorTemplate -suppress "containerType"; editorTemplate -suppress "publishedNode"; editorTemplate -suppress "publishedNodeInfo"; editorTemplate -suppress "publishedNodeType"; editorTemplate -endScrollLayout; }