// =========================================================================== // 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: // AEassemblyDefinitionTempate // // Description Name; // Creates the attribute editor controls for the assembly definition node. // // Input Value: // nodeName // // Output Value: // None // // First creation of the attribute editor for an assemblyDefinition node. global proc AEassDefAssemblyRepresentationsNew(string $attrName) { rowLayout -numberOfColumns 2; text -label (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefActiveRepresentation")) -align "right"; optionMenu -annotation (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefSelectActiveRep")) -label "" -width 200 assDefActiveRepMenu; setParent ..; text -label ""; string $nodeName = `plugNode $attrName`; string $nodeType = `nodeType $attrName`; string $repTypes[] = `assembly -query -canCreate $nodeName`; string $addRepLabel = (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefAddRep")); string $defaultRep = (uiRes("m_AEassemblyDefinitionTemplate.kDefaultRep")); int $repTypeCnt = 0; for ($repType in $repTypes) { string $typeLabel = `assembly -query -repTypeLabel $repType -type $nodeType`; string $btnLabel = `format -stringArg $typeLabel $addRepLabel`; rowLayout -numberOfColumns 2 -adjustableColumn 1 -columnAttach 1 "left" 146 -columnWidth 2 37; button -label $btnLabel ("assDefAddRepBtn"+$repTypeCnt); text -label ""; setParent ..; $repTypeCnt++; } text -label ""; rowLayout -numberOfColumns 3 -adjustableColumn 2 -columnWidth 3 45 -rowAttach 1 "top" 0; text -label (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefRepresentationList")) -height 20 -align "right"; textScrollList -h 130 -allowMultiSelection false assDefScrollListRepLabel; columnLayout; iconTextButton -annotation (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefMoveUp")) -i1 "moveUp.png" -enable false assDefMoveUpRep; iconTextButton -annotation (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefMoveDown")) -i1 "moveDown.png" -enable false assDefMoveDownRep; setParent ..; setParent ..; frameLayout -label (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefRepAttributes")) -collapse false assDefRepFrameLayout; columnLayout -adjustableColumn 1; textFieldGrp -label (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefRepAttrName")) assDefRepAttrNameValue; textFieldGrp -label (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefRepAttrData")) assDefRepAttrDataValue; iconTextButton -i1 "navButtonBrowse.png" -parent assDefRepAttrDataValue assDefBrowseRepPath; textFieldGrp -label (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefRepAttrLabel")) assDefRepAttrLabelValue; textFieldGrp -label (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefRepAttrType")) -editable false assDefRepAttrTypeValue; rowLayout -numberOfColumns 1 -columnAttach 1 "left" 140; rowLayout -numberOfColumns 2 -columnWidth 1 35 -columnWidth 2 25; iconTextButton -annotation (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefReload")) -i1 "refresh.png" assDefRefreshRep; iconTextButton -annotation (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefDelete")) -i1 "smallTrash.png" assDefDeleteRep; setParent ..; setParent ..; setParent ..; setParent ..; AEassDefAssemblyRepresentationsReplace($attrName); } // Update and replace components of the attribute editor for an assemblyDefinition node. global proc AEassDefAssemblyRepresentationsReplace(string $attrName) { string $nodeName = `plugNode $attrName`; optionMenu -edit -changeCommand ("AEassDefChangeActiveMenuRep " + $attrName) assDefActiveRepMenu; textScrollList -edit -selectCommand ("AEassDefShowAttrInfo \"" + $attrName + "\"" ) assDefScrollListRepLabel; iconTextButton -edit -command ("AEassDefReloadActiveRep \""+$nodeName+"\"") assDefRefreshRep; iconTextButton -edit -command ("AEassDefDeleteRepAttr \""+$attrName+"\"") assDefDeleteRep; iconTextButton -edit -command ("AEassDefMoveUpDownRepAttr\""+$attrName+"\" " + 1 ) assDefMoveUpRep; iconTextButton -edit -command ("AEassDefMoveUpDownRepAttr\""+$attrName+"\" " + 0 ) assDefMoveDownRep; iconTextButton -edit -command ("AEassDefBrowsePath \""+$nodeName+"\"") assDefBrowseRepPath; string $repTypes[] = `assembly -query -canCreate $nodeName`; int $repTypeCnt = 0; for ($repType in $repTypes) { button -edit -command ("assemblyCreateRepresentation \""+$repType+"\" \"" + $nodeName + "\"") ("assDefAddRepBtn"+$repTypeCnt); $repTypeCnt++; } AEassDefUpdateComponents($attrName,1); } // Update menus and scroll list items. global proc AEassDefUpdateComponents(string $attrName, int $selectActiveRep) { AEassDefFillMenu($attrName, "assDefActiveRepMenu"); AEassDefFillScrollListLabel($attrName,$selectActiveRep); } // Move representations attributes content per index, up and down the list. global proc AEassDefMoveUpDownRepAttr(string $attrName, int $moveUp) { int $offset = 0; if($moveUp){ $offset = 2; } int $selItems[] = `textScrollList -query -selectIndexedItem assDefScrollListRepLabel`; // Only one item can be selected in the scroll list, we blocked the multi-selection. int $index = $selItems[0]; if(($index - $offset) >= 0) { string $nameAttr = `getAttr ($attrName+"[" + ($index - $offset) + "].repName")`; string $dataAttr = `getAttr ($attrName+"[" + ($index - $offset) + "].repData")`; string $labelAttr = `getAttr ($attrName+"[" + ($index - $offset) + "].repLabel")`; string $typeAttr = `getAttr ($attrName+"[" + ($index - $offset) + "].repType")`; setAttr ($attrName+"[" + ($index - $offset) + "].repName") -type "string" `getAttr ($attrName+"[" + ($index -1) + "].repName")`; setAttr ($attrName+"[" + ($index - $offset) + "].repData") -type "string" `getAttr ($attrName+"[" + ($index -1) + "].repData")`; setAttr ($attrName+"[" + ($index - $offset) + "].repLabel") -type "string" `getAttr ($attrName+"[" + ($index -1) + "].repLabel")`; setAttr ($attrName+"[" + ($index - $offset) + "].repType") -type "string" `getAttr ($attrName+"[" + ($index -1) + "].repType")`; setAttr ($attrName+"[" + ($index - 1) + "].repName") -type "string" $nameAttr; setAttr ($attrName+"[" + ($index - 1) + "].repData") -type "string" $dataAttr; setAttr ($attrName+"[" + ($index - 1) + "].repLabel") -type "string" $labelAttr; setAttr ($attrName+"[" + ($index - 1) + "].repType") -type "string" $typeAttr; AEassDefUpdateComponents($attrName,0); // re-select the label in the scroll list int $selectIndex = ($moveUp == 1) ? $index - 1 : $index + 1; textScrollList -edit -selectIndexedItem $selectIndex assDefScrollListRepLabel; AEassDefShowAttrInfo($attrName); } else { error((uiRes("m_AEassemblyDefinitionTemplate.kAEassDefMoveUpDownIndexError"))); } } // Remove a representation and remap indexes. global proc AEassDefDeleteRepAttr(string $attrName) { string $nodeName = `plugNode $attrName`; int $nbItems = `textScrollList -query -numberOfItems assDefScrollListRepLabel`; int $selItems[] = `textScrollList -query -selectIndexedItem assDefScrollListRepLabel`; // Only one item can be selected in the scroll list, we blocked the multi-selection. int $index = $selItems[0]; string $repName = `textFieldGrp -query -text assDefRepAttrNameValue`; string $repActive = `assembly -query -active $nodeName`; // If we are about to remove the active representation, set it to 'None' first. if($repName == $repActive){ assembly -edit -active "" $nodeName; } if($nbItems != $index) { for ($i = $index; $i < $nbItems; $i++) { setAttr ($attrName+"[" + ($index - 1) + "].repName") -type "string" `getAttr ($attrName+"[" + $index + "].repName")`; setAttr ($attrName+"[" + ($index - 1) + "].repData") -type "string" `getAttr ($attrName+"[" + $index + "].repData")`; setAttr ($attrName+"[" + ($index - 1) + "].repLabel") -type "string" `getAttr ($attrName+"[" + $index + "].repLabel")`; setAttr ($attrName+"[" + ($index - 1) + "].repType") -type "string" `getAttr ($attrName+"[" + $index + "].repType")`; $index++; } removeMultiInstance -break true ($attrName+"[" + ($nbItems -1) + "]"); } else { textScrollList -edit -deselectAll assDefScrollListRepLabel; removeMultiInstance -break true ($attrName+"[" + ($nbItems -1) + "]"); } // re-select the assembly definition node to stay in the attribute editor. // Note: That can be ugly with nested assembly definition because the top assemblyDefinition parent will be selected after // we delete a representation in the child assemblyDefinition. So we can quickly see the parent attribute editor before // our assembly definition selection. select -r $nodeName; } // Change the active representation by the assDefActiveRepMenu selection. global proc AEassDefChangeActiveMenuRep(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 assDefActiveRepMenu`; string $nodeName = `plugNode $attrName`; if($menuIndex != `optionMenu -query -numberOfItems assDefActiveRepMenu`) { 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 and force the selection of the active representation. AEassDefUpdateComponents($attrName,1); }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 AEassDefFillMenu($attrName, "assDefActiveRepMenu"); } else { AEassDefFillScrollListLabel($attrName,0); } } } // Reload the representation, set to active if it was not. global proc AEassDefReloadActiveRep(string $nodeName) { string $repName = `textFieldGrp -query -text assDefRepAttrNameValue`; // 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 AEassDefFillMenu(string $attrName, string $menuName) { string $nodeName = `plugNode $attrName`; string $menuItems[] = `optionMenu -query -itemListLong $menuName`; string $representations[] = `assembly -query -listRepresentations $nodeName`; string $menuItemActiveLabel = (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefMenuActiveLabel")); string $menuItemNoneLabel = (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefMenuNoneLabel")); 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; if($menuName == "assDefActiveRepMenu") { if ($nbRep > 0) { string $activePath = `assembly -query -active $nodeName`; if (size($activePath) > 0) { // select by index instead of label, in case of duplicates. // 1-based int $itemCnt = 1; string $repName; for ($repName in $representations) { if($repName == $activePath){ break; } $itemCnt++; } optionMenu -edit -enable true -select $itemCnt assDefActiveRepMenu; } else { optionMenu -edit -enable true -value $menuItemNoneLabel assDefActiveRepMenu; } } else { optionMenu -edit -enable false -value $menuItemNoneLabel assDefActiveRepMenu; } } if ($oldMenuParent != $menuName) { setParent -menu $oldMenuParent; } } // Fill the representation label scroll list. global proc AEassDefFillScrollListLabel(string $attrName, int $selectActive) { string $nodeName = `plugNode $attrName`; string $listItems[] = `textScrollList -query -allItems assDefScrollListRepLabel`; int $nbRep = `getAttr -size $attrName`; // remove old list items if (size($listItems) > 0){ textScrollList -edit -removeAll assDefScrollListRepLabel; } if($nbRep > 0) { // fill scroll list items for ($i = 0; $i < $nbRep; $i++){ textScrollList -edit -append `getAttr ($attrName+"[" + $i + "].repLabel")` assDefScrollListRepLabel; } 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 assDefScrollListRepLabel`; int $itemCnt = 0; for($item in $items) { if($item == $repActiveLabel) { if($repActive == `getAttr ($attrName+"[" + $itemCnt + "].repName")`) { // force to select the active representation label in the scroll list. if($selectActive){ textScrollList -edit -selectIndexedItem ($itemCnt+1) assDefScrollListRepLabel; AEassDefShowAttrInfo($attrName); } textScrollList -edit -lineFont ($itemCnt+1) "boldLabelFont" assDefScrollListRepLabel; break; } } $itemCnt++; } }else{ // No active representation, select the first item on the list. textScrollList -edit -selectIndexedItem 1 assDefScrollListRepLabel; AEassDefShowAttrInfo($attrName); } textFieldGrp -edit -enable true assDefRepAttrNameValue; textFieldGrp -edit -enable true assDefRepAttrDataValue; textFieldGrp -edit -enable true assDefRepAttrLabelValue; textFieldGrp -edit -enable true assDefRepAttrTypeValue; iconTextButton -edit -enable true assDefDeleteRep; } else { // disable and clean representation attributes component if the representation list is empty. textFieldGrp -edit -text "" -enable false assDefRepAttrNameValue; textFieldGrp -edit -text "" -placeholderText "" -annotation "" -enable false assDefRepAttrDataValue; textFieldGrp -edit -text "" -enable false assDefRepAttrLabelValue; textFieldGrp -edit -text "" -enable false assDefRepAttrTypeValue; iconTextButton -edit -enable false assDefRefreshRep; iconTextButton -edit -enable false assDefDeleteRep; iconTextButton -edit -enable false assDefMoveUpRep; iconTextButton -edit -enable false assDefMoveDownRep; } } // Show the representations attributes. global proc AEassDefShowAttrInfo(string $attrName) { int $selectedIndex[] = `textScrollList -query -selectIndexedItem assDefScrollListRepLabel`; int $nbItems = `textScrollList -query -numberOfItems assDefScrollListRepLabel`; if($nbItems > 0 && $selectedIndex[0] > 0) { iconTextButton -edit -enable ($selectedIndex[0] > 1) assDefMoveUpRep; iconTextButton -edit -enable ($selectedIndex[0] < $nbItems) assDefMoveDownRep; // 1-based to 0-based int $index = ($selectedIndex[0] - 1); string $repName = `getAttr ($attrName+"[" + $index + "].repName")`; string $repData = `getAttr ($attrName+"[" + $index + "].repData")`; string $repLabel = `getAttr ($attrName+"[" + $index + "].repLabel")`; string $repType = `getAttr ($attrName+"[" + $index + "].repType")`; textFieldGrp -edit -text $repName -changeCommand ("AEassDefChangeAttrName \"" + $attrName + "\" " + $index) assDefRepAttrNameValue; textFieldGrp -edit -text $repData -changeCommand ("AEassDefChangeAttrData \"" + $attrName + "\" " + $index) assDefRepAttrDataValue; textFieldGrp -edit -text $repLabel -changeCommand ("AEassDefChangeAttrLabel \"" + $attrName + "\" " + $index) assDefRepAttrLabelValue; textFieldGrp -edit -text $repType assDefRepAttrTypeValue; string $nodeName = `plugNode $attrName`; string $repActive = `assembly -query -active $nodeName`; iconTextButton -edit -enable ($repName == $repActive) assDefRefreshRep; // Specific per representation type AE update procedure string $AEupdateRepProc = `adskRepresentation -q -updateAERepresentationProc $repType`; if($AEupdateRepProc !=""){ string $frameLayoutParent = `setParent -query assDefRepFrameLayout`; eval($AEupdateRepProc + " " + $frameLayoutParent); } } } // Change the repLabel attribute value. global proc AEassDefChangeAttrLabel(string $attrName, int $index) { int $selectedIndex[] = `textScrollList -query -selectIndexedItem assDefScrollListRepLabel`; // Validate that "changeCommand" has not been triggered by a text change from a switched item of the scroll list if($selectedIndex[0] == $index+1) { string $newRepAttrLabel = `textFieldGrp -query -text assDefRepAttrLabelValue`; setAttr ($attrName+"[" + $index + "].repLabel") -type "string" $newRepAttrLabel; AEassDefUpdateComponents($attrName,0); // re-select the new label in the scroll list textScrollList -edit -selectIndexedItem $selectedIndex[0] assDefScrollListRepLabel; string $nodeName = `plugNode $attrName`; if(size(`assembly -query -active $nodeName`) == 0) { // Updating the representation label scroll list // with an active representation set to 'none' // will set and show the attribute info of the first item on the list. // Force an update with our current selection. AEassDefShowAttrInfo($attrName); } } } // Change the repName attribute value. global proc AEassDefChangeAttrName(string $attrName, int $index) { int $selectedIndex[] = `textScrollList -query -selectIndexedItem assDefScrollListRepLabel`; // Validate that "changeCommand" has not been triggered by a text change from a switched item of the scroll list if($selectedIndex[0] == $index+1) { string $repName = `getAttr ($attrName+"[" + $index + "].repName")`; string $newRepAttrName = `textFieldGrp -query -text assDefRepAttrNameValue`; setAttr ($attrName+"[" + $index + "].repName") -type "string" $newRepAttrName; // Re-activate, if it was active, the representation with the corresponding active name. // Since the active representation is not an attribute we cannot just change the attribute value. string $nodeName = `plugNode $attrName`; if($repName == `assembly -query -active $nodeName`){ assembly -edit -active $newRepAttrName $nodeName; select -r $nodeName; } } } // Change the repData attribute value. global proc AEassDefChangeAttrData(string $attrName, int $index) { int $selectedIndex[] = `textScrollList -query -selectIndexedItem assDefScrollListRepLabel`; if($selectedIndex[0] == $index+1) { string $nodeName = `plugNode $attrName`; string $repName = `getAttr ($attrName+"[" + $index + "].repName")`; string $repActive = `assembly -query -active $nodeName`; string $newRepAttrData = `textFieldGrp -query -text assDefRepAttrDataValue`; setAttr ($attrName+"[" + $index + "].repData") -type "string" $newRepAttrData; // Re-activate the representation to re-load it. // If it was the active one. if($repName == $repActive){ if(catch(`assembly -edit -active $repActive $nodeName`)){ assembly -edit -active "" $nodeName; } select -r $nodeName; } } } // Popup a custom representation type browser to change the repData value. global proc AEassDefBrowsePath(string $nodeName) { string $repType = `textFieldGrp -query -text assDefRepAttrTypeValue`; string $repMgrType = `nodeType $nodeName`; string $repPreCreateUIProc = `assembly -q -repPreCreateUIProc $repType -type $repMgrType`; string $newPath = ""; if (size($repPreCreateUIProc)) { $newPath = eval($repPreCreateUIProc); if(size($newPath) > 0){ textFieldGrp -edit -text $newPath -forceChangeCommand assDefRepAttrDataValue; } } } global proc AEassemblyDefinitionTemplate(string $nodeName) { editorTemplate -beginScrollLayout; AEtransformMain $nodeName; editorTemplate -beginLayout (uiRes("m_AEassemblyDefinitionTemplate.kAEassDefAssemblyRep")) -collapse false; editorTemplate -callCustom "AEassDefAssemblyRepresentationsNew" "AEassDefAssemblyRepresentationsReplace" "representations"; editorTemplate -endLayout; AEtransformNoScroll $nodeName; editorTemplate -addExtraControls; // suppresses attributes 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; }