Node Wrangler!

Let your nodes arrange themselves!


I challenged myself to some coding this past long-weekend. I have a nice big list of all the features I wish Blender had, and despite my recent addiction to python, are all way too hardcore for me to code myself… that is until now.

At work we use Maya mostly, so I often find a neat little feature that I wish Blender had and add it to my list. This time it was little button that arranged all your nodes for you, all nice and neat and linear. Surely something like this can’t be that hard to code, right? Well the more I thought about it, the more problems I found.

I checked out some weird and wonderful methods that other software uses, like Spring Force Directed Layouts where you basically simulate the nodes as if each connection was a spring to attract two nodes together, and all nodes that don’t connect, repel each other. After some simulation you get a pretty perfect node tree. Magic right?

The problem is that this technique is more for multi-directional graphs.


At least that was my excuse. Implementing physics algorithms is mostly beyond me for the time being.

So instead I did the logical approach. Fetch all the nodes that have no inputs (start nodes), and look at the nodes that connect to these. Put them to the right of the start nodes, then repeat for all nodes.

Node Wrangler UI

This ends up with one big long overlapping stream of nodes. So to separate them, I did another loop in all the nodes, if one overlaps another, move it down (by the dimensions of the node it collides with – thanks to lukas_t for adding this to the python API by my request!)

And after a couple more loops to make sure everything runs from left to right, it’s basically done.

Apart from this, I also added a button to delete all unused nodes and a tool to display the Backdrop image nicely fit in the window, but those were pretty tedious after the arranging thing.

So I suppose this means I should start tackling some more epic coding projects.

I work with nodes a heck of a lot, so if you’ve got an idea or request for an addon, let me know :) If you convince me that it’d be useful, I’ll do it for ya!