8
$\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$
8
+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$
  • $\begingroup$ I can't tell if I should just delete my answer now that you have answered it far better. $\endgroup$ – Ray Mairlot May 21 '17 at 16:06
  • $\begingroup$ What a mess... Thanks @zeffii. Is there a way get all custom groups in this way too? $\endgroup$ – brockmann May 21 '17 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 May 21 '17 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 May 22 '17 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 May 22 '17 at 8:39
5
$\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$
  • 1
    $\begingroup$ Thanks. Is there any way to get the categories too? $\endgroup$ – brockmann May 17 '17 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$ – Ray Mairlot May 17 '17 at 13:09
  • $\begingroup$ If this answer has helped you, please consider accepting it. See: stackoverflow.com/help/accepted-answer $\endgroup$ – Ray Mairlot May 17 '17 at 13:14
  • $\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 May 17 '17 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$ – Ray Mairlot May 17 '17 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.