SHARE
TWEET

Untitled

a guest Jul 24th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // to call this function no need to select the composite in the node view, it will be chosen with a prompt.
  2.  
  3. function ConnectButton(){
  4.     if (KeyModifiers.IsAlternatePressed()){
  5.         disconnectAllSellNodes()
  6.     }else{
  7.         connectAllSellNodes()
  8.     }
  9. }
  10.  
  11.  
  12. function connectAllSellNodes(){
  13.     // connects selected Nodes to a chosen Composite
  14.     scene.beginUndoRedoAccum("connectAllSelNodes");
  15.  
  16.     // filter out some nodes types
  17.     var typesFilter = ["PEG"]
  18.     var sel = selection.selectedNodes()
  19.     sel = sel.filter(function(x){return typesFilter.indexOf(node.type(x)) == -1})
  20.  
  21.     // get nodes sorted by coordinates
  22.     sel = sel.sort(function (b,a){return (node.coordY(a)*10000+node.coordX(a)) - (node.coordY(b)*10000+node.coordX(b))});
  23.  
  24.     if (sel.length==0) return;
  25.  
  26.     var homeGroup = node.parentNode(sel[0])
  27.     var sceneComps = getSceneComposites(homeGroup);
  28.  
  29.     // prompt for a composite to connect to if there is more than  one
  30.     if (sceneComps.length > 1){
  31.         var compsNames = sceneComps.map(function(x){return node.getName(x)})
  32.         var comp =  homeGroup+"/"+Input.getItem("Select a composite to link to:", compsNames); 
  33.     }else{
  34.         var comp =  sceneComps[0]
  35.     }
  36.  
  37.     // link the nodes to the comp
  38.     for (var i in sel){
  39.         MessageLog.trace("linking node "+sel[i]+" "+" to "+comp)
  40.         node.link(sel[i], 0, comp, node.numberOfInputPorts(comp)+1)
  41.     }
  42.  
  43.     scene.endUndoRedoAccum();
  44.  
  45. }
  46.  
  47.  
  48. function disconnectAllSellNodes(){
  49.  
  50.     scene.beginUndoRedoAccum("disconnectAllSelNodes");
  51.  
  52.     var sel = selection.selectedNodes();
  53.     for (var i in sel){
  54.         for (var j=0; j<node.numberOfOutputPorts(sel[i]); j++){
  55.             for (var k=0; k<node.numberOfOutputLinks(sel[i], j); j++){
  56.                 var dstNode = node.dstNode(sel[i], j, k)
  57.                 var port = getInputPort(sel[i], dstNode)
  58.                 if (port != -1) node.unlink(dstNode, port)
  59.             }
  60.         }
  61.     }
  62.  
  63.     scene.endUndoRedoAccum();
  64. }
  65.  
  66.  
  67. function getSceneComposites(group){
  68.     // returns a sorted list of all the composite Nodes in a group
  69.     var nodes = node.subNodes(group).filter(function(x){return node.type(x) == "COMPOSITE"})
  70.     return nodes.sort(function (a,b){return (node.coordY(a)*10000+node.coordX(a)) - (node.coordY(b)*10000+node.coordX(b))});
  71. }
  72.  
  73.  
  74. function getInputPort(srcNode, dstNode){
  75.     // find the InPort through which two nodes are connected
  76.     for (var i=0; i<node.numberOfInputPorts(dstNode); i++){
  77.         var linkedNode = node.srcNode(dstNode, i);
  78.         if (linkedNode == srcNode) return i;
  79.     }
  80.     return -1
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top