10
$\begingroup$

The node editor is constantly changing due to cycles. There are new nodes in every release of blender so I'd like to know whether there is a way to get all available node types in a list. I remembered that Node Wrangler has this beautiful "switch my node to something else" thing, which I thought already implements that functionality. However, all nodes are hard coded like that:

shaders_output_nodes_props = (
    ('ShaderNodeOutputMaterial', 'OUTPUT_MATERIAL', 'Material Output'),
    ('ShaderNodeOutputLamp', 'OUTPUT_LAMP', 'Lamp Output'),
    ('ShaderNodeOutputWorld', 'OUTPUT_WORLD', 'World Output'),
)

Q: Is there a way to get a complete list of all available node types by category and ideally all custom groups as well with bpy.types or something similar?

$\endgroup$

3 Answers 3

15
+50
$\begingroup$

This addresses the second part of your question. How to auto generate all this.

Node Category (cycles) and each registered node.bl_idname in the category

import bpy

ddir = lambda data, filter_str: [i for i in dir(data) if i.startswith(filter_str)]
get_nodes = lambda cat: [i for i in getattr(bpy.types, cat).category.items(None)]

cycles_categories = ddir(bpy.types, "NODE_MT_category_SH_NEW")
for cat in cycles_categories: 
    print(cat)
    for node in get_nodes(cat):
        print('bl_idname: {node.nodetype}, type: {node.label}'.format(node=node))      

Output is (snipped):

NODE_MT_category_SH_NEW_CONVERTOR
bl_idname: ShaderNodeBlackbody, type: Blackbody
bl_idname: ShaderNodeValToRGB, type: ColorRamp
bl_idname: ShaderNodeCombineHSV, type: Combine HSV
bl_idname: ShaderNodeCombineRGB, type: Combine RGB
bl_idname: ShaderNodeCombineXYZ, type: Combine XYZ
bl_idname: ShaderNodeMath, type: Math
bl_idname: ShaderNodeRGBToBW, type: RGB to BW

Custom Node Groups of type ShaderNodeTree

[ng for ng in bpy.data.node_groups if ng.bl_idname == 'ShaderNodeTree']
$\endgroup$
7
  • $\begingroup$ I can't tell if I should just delete my answer now that you have answered it far better. $\endgroup$ Commented May 21, 2017 at 16:06
  • $\begingroup$ What a mess... Thanks @zeffii. Is there a way get all custom groups in this way too? $\endgroup$
    – brockmann
    Commented May 21, 2017 at 16:08
  • $\begingroup$ @RayMairlot keep your answer, someone might invest time in making a "prettier" answer than this silly example of mine :). $\endgroup$
    – zeffii
    Commented May 21, 2017 at 17:02
  • 1
    $\begingroup$ Right, didn't meant your code. I meant that the majority of blender's API is well designed (far better than in many other DCC's). However when it comes to the node editor it feels mad sometimes. In this case that's a heavy iteration to get 30 node types (IMHO). Nevermind, many many thanks for posting that @zeffii $\endgroup$
    – brockmann
    Commented May 22, 2017 at 8:34
  • 2
    $\begingroup$ I agree, some of parts of the API are a little lacking. Iterate once, and then cache it in a dict. $\endgroup$
    – zeffii
    Commented May 22, 2017 at 8:39
8
$\begingroup$

Yes, this is possible in a similar way to Best way to get a list of modifiers in Python?

You can use bpy.types.ShaderNode.__subclasses__() to see everything which uses ShaderNode as its base, e.g. the Cycles nodes.

This returns a list of all the nodes, from which you can extract information. Below, I collect the identifier of each node and then print them out:

import bpy

nodes = [node.bl_rna.identifier for node in bpy.types.ShaderNode.__subclasses__()]

for node in nodes:
    print(node)

Result:

ShaderNodeLightFalloff
ShaderNodeBsdfVelvet
ShaderNodeCombineXYZ
ShaderNodeBackground
ShaderNodeHoldout
ShaderNodeTexPointDensity
ShaderNodeMaterial
etc...
etc..
etc.

Using node.bl_rna.name instead of node.bl_rna.identifier would result in:

Light Falloff
Velvet BSDF
Combine XYZ
Background
Holdout
Point Density
Material
etc...
etc..
etc.

To explore the available properties, e.g. identifier, name etc. you can enter this in the Python Console:

nodes = bpy.types.ShaderNode.__subclasses__()

Then to access a single node type this and press Ctrl+Space to autocomplete and show the available options:

nodes[0].bl_rna.   
$\endgroup$
8
  • 2
    $\begingroup$ Thanks. Is there any way to get the categories too? $\endgroup$
    – brockmann
    Commented May 17, 2017 at 12:59
  • $\begingroup$ What do you mean by categories? If you mean the 'Add' menu, I presume that's defined manually. If there is a property on the node that does that, I haven't found it yet. $\endgroup$ Commented May 17, 2017 at 13:09
  • $\begingroup$ If this answer has helped you, please consider accepting it. See: stackoverflow.com/help/accepted-answer $\endgroup$ Commented May 17, 2017 at 13:14
  • 1
    $\begingroup$ Yes, Shader, Texture, Color and so on. Populating a complete list would be awesome, furthermore your solution not work for custom groups... (upvoted already) $\endgroup$
    – brockmann
    Commented May 17, 2017 at 14:41
  • $\begingroup$ I think as far as the current question goes, I have answered it, but in regards to your additional comments you should probably add those details into your original question. $\endgroup$ Commented May 17, 2017 at 14:49
1
$\begingroup$
import bpy

def GetAllNodes(target):
    set_result = set()
    for li in bpy.types.__dir__():
        type = getattr(bpy.types, li)
        if hasattr(type,'bl_rna'):
            base = type.bl_rna.base
            while base:
                if base.identifier==target:
                    set_result.add(type.bl_rna.identifier)
                    break
                base = base.bl_rna.base
    return set_result

print(len(GetAllNodes('Node')), "All")
print(len(GetAllNodes('ShaderNode')), "Shader")
print(len(GetAllNodes('GeometryNode')), "Geometry")
print(len(GetAllNodes('CompositorNode')), "Compositor")
print(len(GetAllNodes('TextureNode')), "Texture")
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .