// =========================================================================== // 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: // AEreferenceTempate // // Description Name; // Creates the attribute editor controls for the reference node. // // Input Value: // nodeName // // Output Value: // None // global proc AErefFileNew(string $nodeAttr) { string $buffer[]; tokenize($nodeAttr, ".", $buffer); string $selRefFilePath = ""; string $selRefFilePathReal = ""; string $selRefFileNamespace = ""; string $refNodeName = ""; int $isVisible = 0; int $isLoaded = 0; // catchQuiet in case we are with the sharedReferenceNode // dont't show the ui objects if it's a sharedReferenceNode if(!catchQuiet(`referenceQuery -filename $buffer[0]`)) { $refNodeName = $buffer[0]; $isVisible = 1; $isLoaded = `referenceQuery -isLoaded $refNodeName`; $selRefFilePath = `referenceQuery -filename $refNodeName`; $selRefFilePathReal = `referenceQuery -filename -withoutCopyNumber $refNodeName`; $selRefFileNamespace = `referenceQuery -namespace -shortName $refNodeName`; } setUITemplate -pst attributeEditorTemplate; textFieldGrp -label (uiRes("m_AEreferenceTemplate.kAEReferenceFilePath")) -text $selRefFilePath -enable true -editable false -visible $isVisible referenceFilePathValue; int $refWritable = `filetest -w $selRefFilePathReal`; text -label (uiRes("m_AEreferenceTemplate.kAEReferenceReadOnly")) -enable false -font "obliqueLabelFont" -visible $isVisible refIsReadOnly; if($refWritable == 1){ text -edit -label "" refIsReadOnly; } rowLayout -numberOfColumns 3 -visible $isVisible -columnWidth3 150 26 26 loadUnloadLayout; text -label "" emptySpace; iconTextButton -i1 "reloadReference.png" -annotation (uiRes("m_AEreferenceTemplate.kAEReloadRefFile")) -command ("AEloadUnloadReference(1, \"" + $refNodeName + "\")") reloadRefButton; iconTextButton -i1 "unloadReference.png" -enable $isLoaded -annotation (uiRes("m_AEreferenceTemplate.kAEUnloadRefFile")) -command ("AEloadUnloadReference(0, \"" + $refNodeName + "\")") unloadRefButton; setParent ..; textFieldGrp -label (uiRes("m_AEreferenceTemplate.kAENamespace")) -text $selRefFileNamespace -visible $isVisible -enable true -editable false referenceFileNamespace; setUITemplate -ppt; } global proc AErefFileReplace(string $nodeAttr) { string $buffer[]; tokenize($nodeAttr, ".", $buffer); string $selRefFilePath = ""; string $selRefFilePathReal = ""; string $selRefFileNamespace = ""; string $refNodeName = ""; int $isVisible = 0; int $isLoaded = 0; // catchQuiet in case we are with the sharedReferenceNode // dont't show the ui objects if it's a sharedReferenceNode if(!catchQuiet(`referenceQuery -filename $buffer[0]`)) { $refNodeName = $buffer[0]; $isVisible = 1; $isLoaded = `referenceQuery -isLoaded $refNodeName`; $selRefFilePath = `referenceQuery -filename $refNodeName`; $selRefFilePathReal = `referenceQuery -filename -withoutCopyNumber $refNodeName`; $selRefFileNamespace = `referenceQuery -namespace -shortName $refNodeName`; } textFieldGrp -edit -visible $isVisible -text $selRefFilePath referenceFilePathValue; int $refWritable = `filetest -w $selRefFilePathReal`; if($refWritable == 0){ text -edit -visible $isVisible -label (uiRes("m_AEreferenceTemplate.kAEReferenceReadOnly")) refIsReadOnly; }else{ text -edit -visible $isVisible -label "" refIsReadOnly; } rowLayout -edit -visible $isVisible loadUnloadLayout; iconTextButton -edit -command ("AEloadUnloadReference(1, \"" + $refNodeName + "\")") reloadRefButton; iconTextButton -edit -enable $isLoaded -command ("AEloadUnloadReference(0, \"" + $refNodeName + "\")") unloadRefButton; textFieldGrp -edit -visible $isVisible -text $selRefFileNamespace referenceFileNamespace; } global proc AEloadUnloadReference(int $load, string $refNode) { if(!$load) { file -unloadReference $refNode; }else{ file -loadReference $refNode; } select -r $refNode; } // First argument of "editorTemplate -callCustom". // Create UI objects when a new node type is edited. global proc AESharedRefNodesNew(string $nodeAttr) { // Shared nodes are not attributes, so we can't provide an attribute as argument. // There's a logic behind the attribute editor that expect to have an attribute as argument. // If you provide something else, like in that case where I provide the reference node name, // the resulting argument is myRefRN.myRefRN so we need to split it like if it was an attribute. string $buffer[]; tokenize($nodeAttr, ".", $buffer); string $selRefFile = ""; string $sharedNodes[] = {}; int $i, $sharedCount = 0; int $isVisible = 0; // catchQuiet in case we are with the sharedReferenceNode // dont't show the ui objects if it's a sharedReferenceNode if(!catchQuiet(`referenceQuery -filename $buffer[0]`)) { $isVisible = 1; $selRefFile = `referenceQuery -filename -shortName $buffer[0]`; $sharedNodes = `file -query -sharedNodes $selRefFile`; $sharedCount = size($sharedNodes); } setUITemplate -pst attributeEditorTemplate; checkBoxGrp -numberOfCheckBoxes 1 -label "" -enable1 false -visible $isVisible -label1 (uiRes("m_AEreferenceTemplate.kAEDisplayLayers")) -cw 2 180 refAESharedDisplayLayers; checkBoxGrp -numberOfCheckBoxes 1 -label "" -enable1 false -visible $isVisible -label1 (uiRes("m_AEreferenceTemplate.kAEShadingNetworks")) -cw 2 180 refAESharedShadingNetworks; checkBoxGrp -numberOfCheckBoxes 1 -label "" -enable1 false -visible $isVisible -label1 (uiRes("m_AEreferenceTemplate.kAERenderLayersByName")) -cw 2 180 refAESharedRenderLayerByName; checkBoxGrp -numberOfCheckBoxes 1 -label "" -enable1 false -visible $isVisible -label1 (uiRes("m_AEreferenceTemplate.kAERenderLayersByID")) -cw 2 180 refAESharedRenderLayerByID; setParent ..; setUITemplate -ppt; for($i = 0; $i < $sharedCount; $i++) { if($sharedNodes[$i] == "displayLayers"){ checkBoxGrp -edit -value1 1 refAESharedDisplayLayers; }else if($sharedNodes[$i] == "shadingNetworks"){ checkBoxGrp -edit -value1 1 refAESharedShadingNetworks; }else if($sharedNodes[$i] == "renderLayersByName"){ checkBoxGrp -edit -value1 1 refAESharedRenderLayerByName; }else if($sharedNodes[$i] == "renderLayersById"){ checkBoxGrp -edit -value1 1 refAESharedRenderLayerByID; } } } // Second argument of "editorTemplate -callCustom". // Attribute editor already exists and another node of the same type is now to be edited. // Update the value with the new node of the same type. global proc AESharedRefNodesReplace(string $nodeAttr) { string $buffer[]; tokenize($nodeAttr, ".", $buffer); string $selRefFile = ""; string $sharedNodes[] = {}; int $i, $sharedCount = 0; int $isVisible = 0; // catchQuiet in case we are with the sharedReferenceNode // dont't show the ui objects if it's a sharedReferenceNode if(!catchQuiet(`referenceQuery -filename $buffer[0]`)) { $isVisible = 1; $selRefFile = `referenceQuery -filename -shortName $buffer[0]`; $sharedNodes = `file -query -sharedNodes $selRefFile`; $sharedCount = size($sharedNodes); } // reset values checkBoxGrp -edit -visible $isVisible -value1 0 refAESharedDisplayLayers; checkBoxGrp -edit -visible $isVisible -value1 0 refAESharedShadingNetworks; checkBoxGrp -edit -visible $isVisible -value1 0 refAESharedRenderLayerByName; checkBoxGrp -edit -visible $isVisible -value1 0 refAESharedRenderLayerByID; for($i = 0; $i < $sharedCount; $i++) { if($sharedNodes[$i] == "displayLayers"){ checkBoxGrp -edit -value1 1 refAESharedDisplayLayers; }else if($sharedNodes[$i] == "shadingNetworks"){ checkBoxGrp -edit -value1 1 refAESharedShadingNetworks; }else if($sharedNodes[$i] == "renderLayersByName"){ checkBoxGrp -edit -value1 1 refAESharedRenderLayerByName; }else if($sharedNodes[$i] == "renderLayersById"){ checkBoxGrp -edit -value1 1 refAESharedRenderLayerByID; } } } global proc AErefConnectListNew(string $nodeAttr) { string $buffer[]; tokenize($nodeAttr, ".", $buffer); string $attr = $buffer[1]; setUITemplate -pst attributeEditorTemplate; columnLayout ($attr+"Column"); setParent ..; setUITemplate -ppt; AErefConnectListReplace($nodeAttr); } global proc AErefConnectListReplace(string $nodeAttr) { string $buffer[]; tokenize($nodeAttr, ".", $buffer); string $attr = $buffer[1]; setParent ($attr+"Column"); string $layoutName=`setParent -q`; int $oldCnt=`columnLayout -q -nch $layoutName`; string $dataAry[] = `listAttr -m $nodeAttr`; int $dataCnt = size($dataAry) / 3; for ($i = 0; $i < $dataCnt; $i++) { string $refAttr = `getAttr ($nodeAttr+"["+$i+"].ca")`; string $srcPlugAry[] = `listConnections -s true -d false -p true ($nodeAttr+"["+$i+"].c")`; string $dstPlugAry[] = `listConnections -s false -d true -p true ($nodeAttr+"["+$i+"].c")`; string $btnCmd; string $text; if (size($srcPlugAry)) { $btnCmd = ("disconnectAttr "+$srcPlugAry[0]+" "+$nodeAttr+"["+$i+"].c; "); $btnCmd += ("AErefConnectListReplace(\""+$nodeAttr+"\")"); $text = ($refAttr+" <- "+$srcPlugAry[0]); } else if (size($dstPlugAry)) { $btnCmd = ("disconnectAttr "+$nodeAttr+"["+$i+"].c "+$dstPlugAry[0]+"; "); $btnCmd += ("AErefConnectListReplace(\""+$nodeAttr+"\")"); $text = ($refAttr+" -> "+$dstPlugAry[0]); } else { $btnCmd = ""; $text = ""; } string $rowLayoutName = $attr+"Row"+$i; string $btnName = $attr+"Btn"+$i; string $textFieldName = $attr+"Text"+$i; if ($i < $oldCnt) { button -e -c $btnCmd $btnName; textField -e -text $text $textFieldName; } else { setUITemplate -pst attributeEditorTemplate; rowLayout -nc 2 -ct2 right both $rowLayoutName; button -label (uiRes("m_AEreferenceTemplate.kDisconnect")) -w 100 -c $btnCmd $btnName; textField -ed false -text $text $textFieldName; setParent ..; setUITemplate -ppt; } } for ($i = $dataCnt; $i < $oldCnt; $i++) { string $rowLayoutName = $attr+"Row"+$i; if (`rowLayout -exists $rowLayoutName`) { deleteUI -layout $rowLayoutName; } } setParent ..; } global proc AErefMultiStrNew(string $nodeAttr) { string $buffer[]; tokenize($nodeAttr, ".", $buffer); string $attr = $buffer[1]; setUITemplate -pst attributeEditorTemplate; columnLayout ($attr+"Column"); setParent ..; setUITemplate -ppt; AErefMultiStrReplace($nodeAttr); } global proc AErefMultiStrReplace(string $nodeAttr) { string $buffer[]; tokenize($nodeAttr, ".", $buffer); string $attr = $buffer[1]; setParent ($attr+"Column"); string $layoutName=`setParent -q`; int $oldCnt=`columnLayout -q -nch $layoutName`; string $dataAry[] = `listAttr -m $nodeAttr`; int $dataCnt = size($dataAry); for ($i = 0; $i < $dataCnt; $i++) { string $value = `getAttr ($nodeAttr+"["+$i+"]")`; string $btnCmd = ("setAttr -type \"string\" "+$nodeAttr+"["+$i+"] \"\""); string $rowLayoutName = $attr+"Row"+$i; string $btnName = $attr+"Btn"+$i; string $textFieldName = $attr+"Text"+$i; if ($i < $oldCnt) { button -e -c $btnCmd $btnName; textField -e -text $value $textFieldName; connectControl $textFieldName ($nodeAttr+"["+$i+"]"); } else { setUITemplate -pst attributeEditorTemplate; rowLayout -nc 2 -ct2 right both $rowLayoutName; button -label (uiRes("m_AEreferenceTemplate.kRemove")) -c $btnCmd -w 100 $btnName; textField -ed false -text $value $textFieldName; connectControl $textFieldName ($nodeAttr+"["+$i+"]"); setParent ..; setUITemplate -ppt; } } for ($i = $dataCnt; $i < $oldCnt; $i++) { string $rowLayoutName = $attr+"Row"+$i; if (`rowLayout -exists $rowLayoutName`) { deleteUI -layout $rowLayoutName; } } setParent ..; } global proc AErefLockingDimming(string $nodeAttr) { string $buffer[]; tokenize($nodeAttr, ".", $buffer); string $node = $buffer[0]; editorTemplate -dimControl $node "locked" true; } global proc AEreferenceTemplate(string $nodeName) { editorTemplate -beginScrollLayout; editorTemplate -beginLayout (uiRes("m_AEreferenceTemplate.kFileNames")) -collapse true; editorTemplate -callCustom "AErefFileNew" "AErefFileReplace" "fileName"; editorTemplate -endLayout; editorTemplate -beginLayout (uiRes("m_AEreferenceTemplate.kProxies")) -collapse true; editorTemplate -addControl "proxyTag"; editorTemplate -endLayout; editorTemplate -beginLayout (uiRes("m_AEreferenceTemplate.kSharingRef")) -collapse true; editorTemplate -callCustom "AESharedRefNodesNew" "AESharedRefNodesReplace" $nodeName; editorTemplate -endLayout; editorTemplate -beginLayout (uiRes("m_AEreferenceTemplate.kLocking")) -collapse true; editorTemplate -addControl "locked" "AErefLockingDimming"; editorTemplate -endLayout; // Include all base class and node attributes. // AEdependNodeTemplate $nodeName; // Suppressed attributes editorTemplate -suppress "fileNames"; editorTemplate -suppress "connectionList"; editorTemplate -suppress "connectionAttr"; editorTemplate -suppress "connection"; editorTemplate -suppress "setAttrList"; editorTemplate -suppress "addAttrList"; editorTemplate -suppress "deleteAttrList"; editorTemplate -suppress "brokenConnectionList"; editorTemplate -suppress "parentList"; editorTemplate -suppress "fosterParent"; editorTemplate -suppress "fosterSiblings"; editorTemplate -suppress "placeHolderList"; editorTemplate -suppress "multiParentList"; editorTemplate -suppress "multiParent"; editorTemplate -suppress "edits"; editorTemplate -suppress "proxyMsg"; editorTemplate -suppress "unknownReference"; editorTemplate -suppress "sharedReference"; editorTemplate -suppress "placeHolderNamespace"; editorTemplate -suppress "associatedNode"; editorTemplate -addExtraControls; editorTemplate -endScrollLayout; }