Class for creating nodes by type

Class for quick node creation by their type.

Code by Skarn.

It is convenient to create nodes in a single line by its type with this class. The type of any node is specified in its bl_idname property:

Creating an instance of the class, we pass a pointer to the current node tree to its input parameters. The new nodes will be created in the specified node tree. Now to create a new node, we just need to call the “add_node” method, specifying the node type, name to set, and location by the columns and rows indexes in the parameters. The method returns a pointer to the created node, which allows to easily change its default parameters ​​if necessary.

Code usage example:

Here we define an instance of the class to work with the current node tree. Next, we create two nodes “UVMap” and “ImageTexture”, change their parameters, and connect them together by node links.


Author: Nikita

Blender add-ons developer and articles writer.