How to show all available nodes

We can get a list of all available shader nodes by their type.

To start, add any object to the scene, for example, a cube, create material for it, and delete all nodes. Here, in this material, we will display all the shader nodes available in Blender.

We can get all available types of shader nodes using the “bpy.types” structure. It stores a list of all object types available in the Blender API, including nodes.

With executing this command

we will get a list of the names of all the object types available through the Blender Python API.

All types of shader nodes are inherited from the “ShaderNode” type. Therefore, to get only the shader node types from the general list, we need to check whether a particular type is inherited from “ShaderNode”.

Checking the inheritance of one type from another can be performed using the command

It will return “True” if the _CHECK_TYPE_ type is inherited from the _PARENT_TYPE_ type.

The “issubclass” function compares the types but not their text identifiers that we got through the “dir” function. To get the type itself by its text name, we use the fact that in Python any type is at the same time an attribute of the module in which it is described. So, we can get the type described in “bpy.types” with the command:

Having a list of nodes types we can add the nodes themselves to the current material by their type.

A pointer to the current node tree, in which we will add nodes, can be got as follows:

Set the initial values ​​for the location of the nodes.

Let’s cycle through all the possible types of API objects:

and if the type inherits from “ShaderNode”

add a node of this type to the node tree, and set the width and offset for it.

Final code:

We will enclose the part of the code that adds the node to the node tree in the “try – except” block to prevent errors when trying to create an abstract node that has no visual form, for example, the “ShaderNode”.

After executing this code, all available nodes will be sequentially added to the material.

0 0 votes
Article Rating
Notify of

0 Comment
Inline Feedbacks
View all comments