Moving node tree to the node editor area origin

In Blender, when creating complex procedural materials or geometry nodes, the node tree often moves away from the starting point of the node editor area. Later, when working with materials, this causes some inconvenience – when switching from material to material, the node tree “runs away” and we have to scroll the screen each time to see the nodes. This problem can be solved using a simple script that will move the entire node tree to the origin of the node editor area.

To shift the entire node tree to the origin without distortion, we will start from the current active node. We will move it to the origin of the area, coordinates (0.0, 0.0). All other nodes will be shifted relative to it by exactly the same vector.

Shader Editor

Let’s take the active node

And get its coordinates

This is the vector by which we need to shift all the nodes.

We use copy() to get a static copy of the values, otherwise when the active node moves to the origin, this values will be lost.

Now for each node, recalculate the coordinates, subtracting the shift vector from the current coordinates of the node.

Full script code:

Let’s execute this script for each material and centralize the node editor area by pressing the dot key (Del) on the numeric part of the keyboard.

Now, when switching materials, we no longer need to scroll the window in search of nodes, it will always be centered on the starting point.

Geometry Nodes Editor

For the Geometry Nodes area, everything works exactly the same.

The active node:

Static copy of its coordinates – our shift vector:

Moving each node by this vector:

Full script code:

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments