top of page

Automatic Connections

Do you ever find yourself making the same connections in the node editor over and over? Like connecting a curves world space attribute to a "motion path" or a " point on curve info" node. I know I did. So I wrote up a neat little script to automate that process.

It's hard to post the whole script in a readable form here so here's a link to it so you can look at it in the script editor while reading through this little explanation.

So the script has two parts, a dictionary and some code. Every entry in the dictionary looks like this

'[transform,composeMatrix]':[ 'over', ['t','it'],['r','ir'],['s','is'] ]

or more generally

[source,target]:['connection_method' , [source_attr,target_attr],[source_attr,target_attr] ]

So the key to each entry is a pairing off two node types, and the entry is a list whose first object is string that tells us how to make the connection. The rest of the objects in the list are lists made up of pairs of attributes.

The script looks at the nodes you have selected, it treats the first one you selected as the source, and the rest as targets. For each target it checks if the string '[source node type, target node type]' is in the dictionary.

If it is then it looks it up and gets the entry. Then it checks if the connection method is 'over', 'first_open', or 'multi'.


If the connection method is over then it goes through the attribute pairings and makes those connections (overwriting any existing connections). So in the example:

'[transform,composeMatrix]':[ 'over', ['t','it'],['r','ir'],['s','is'] ]

It would connect the translate, rotate, and scale attributes of the transform node to the input translate, input rotate, and input scale attributes of the composeMatrix node.


If the connection method is first open it runs through the attribute pairings and the first one that has no incoming connection. So in the example:

'[locator,blendColors]':[ 'first_open', ['wp[0]','color1'],['wp[0]','rcolor2']]

It tries to connect the locators worldPosition attribute to the blendColors color1 attribute, and if that already has an incoming connection then it tries to connect to color2, and if they both have an incoming connection then it does nothing, it never overrides existing connections.


If the connection method is multi then it goes through the attribute pairings and checks to see if the input has already has an incoming connection, if it does then it checks the next attribute in the multi attribute until it finds an open one, then it makes the connections. So in the example:

'[fourByFourMatrix,wtAddMatrix]':[ 'multi', ['output','wtMatrix[%].matrixIn']]

It tries to connect the output attribute of the fourByFourMatrix node to the wtMatrix[0].matrixIn attribute of the wtAddMatrix node, and if there's already an incoming connection it tries wtMatrix[1].matrixIn, wtMatrix[2].matrixIn and so on until it finds one without an incoming connection.


Now not all node pairings are in the dictionary, that would be crazy, but it does contain over 50 pairings. I only put a pairing into the dictionary if there is only one valid connection between the two nodes, or if I always make the same connection between the nodes, like with transform and compose matrix nodes. I hooked this script up to a hotkey and it has been a big time saver while testing out new ideas.

Featured Posts
Recent Posts
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page