// =========================================================================== // 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. // =========================================================================== global proc int hypergraphConnectionEndMenu(string $editor, string $menu, string $node, string $plugName, string $direction, string $type, string $disconnectPlug) // // Description: // Called to complete a connection when using the popup connection // editing capability in the Hypergraph and Hypershade. It is // passed the source plug for the connection and direction so the // popup menu that is built only shows attributes that are compatible // with the source plug // { string $title; string $attrCmd; string $cmd; if($direction == "from") { $title = "Inputs"; $attrCmd = "attributeMenu -inputs "+$node+" -attrType "+$type; }else{ $title = "Outputs"; $attrCmd = "attributeMenu -outputs "+$node+" -attrType "+$type; } int $numElements = 2; string $nodeFrom; string $nodeTo; string $attrs[] = `eval $attrCmd`; if($direction == "from") { $nodeFrom = $plugName; }else{ $nodeTo = $plugName; } int $postMenu; int $length = size($attrs); if($length == $numElements) { if($direction == "from") { $nodeTo = $node+"."+$attrs[0]; }else{ $nodeFrom = $node+"."+$attrs[0]; } string $plug = `connectionInfo -sfd $nodeTo`; if($plug != "") { disconnectAttr $plug $nodeTo; } if(!`isConnected $nodeFrom $nodeTo`) { connectAttr $nodeFrom $nodeTo; } $postMenu = 0; }else if($length != 0) { setParent -m $menu; popupMenu -e -deleteAllItems $menu; menuItem -l $title; menuItem -divider true; string $dis; if($direction == "from") { $nodeTo = $node; }else{ $nodeFrom = $node; string $plug = `connectionInfo -sfd $nodeTo`; if($plug != "") { $dis = "disconnectAttr "+$plug+" "+$nodeTo+";"; } } string $newPlug; int $i = 0; for ($i = 0 ; $i < $length ; $i += $numElements) { string $name = $attrs[$i]; int $italicize = ($attrs[$i+1] == "Connected"); // Attribute is a source and node is the destination // if($direction == "from") { $dis = ""; // If moving an existing connection then disconnect the old one // This is the more common left to right connection // if($disconnectPlug != "") { $dis = "disconnectAttr "+$nodeFrom+" "+$disconnectPlug+";"; } // If connecting to an already connected input then remove // its existing connection to avoid a fan in // $newPlug = $nodeTo+"."+$attrs[$i]; string $plug = `connectionInfo -sfd $newPlug`; if($plug != "") { $dis = $dis + "disconnectAttr "+$plug+" "+$newPlug+";"; } // Build the menu item with the command // menuItem -l $attrs[$i] -italicized $italicize -boldFont $italicize -c ($dis+"connectAttr "+$nodeFrom+" "+$newPlug); // Attribute is a destination and node is the source. // This is the less common right to left connection // }else{ $newPlug = $nodeFrom+"."+$attrs[$i]; menuItem -l $attrs[$i] -italicized $italicize -boldFont $italicize -c ($dis+"connectAttr "+$newPlug+" "+$nodeTo); } } $postMenu = 1; } return $postMenu; }