0
$\begingroup$

Before 4.0, you were able to run a script like this:

import bpy
bpy.data.node_groups['NODE_GROUP_NAME'].inputs.new('NodeSocketFloat', 'SOCKET_NAME')

and it would allow you to use any socket type used in blender, including geometry node exclusive ones such as boolean, integer, string, etc.

In 4.0, the API for node groups changed, so I tried modifying the code like this:

import bpy
bpy.data.node_groups['NODE_GROUP_NAME'].interface.new_socket(name='SOCKET_NAME', socket_type='NodeSocketFloat')

which works for the shader node-supported sockets (including boolean and integer, as those seem to now be properly supported in shader nodes), but if you try to add any other node type, such as NodeSocketMenu, it will give you an error:

TypeError: NodeTreeInterface.new_socket(): error with keyword argument "socket_type"
-  enum "NodeSocketMenu" not found in ('NodeSocketBool', 'NodeSocketVector',
'NodeSocketInt', 'NodeSocketShader', 'NodeSocketFloat', 'NodeSocketColor')

which implies they removed the option to add unsupported sockets to shader nodes. However, appending a node group from a previous version that did have unsupported nodes (eg. string, image, material, etc.) still works. For the string type specifically, you can even just use the string inputs from the Principled Volume node in a node group and it will still work. So are unsupported node sockets in shader nodes possible in 4.0+, but just not via python or something? I'm trying to get the new menu socket in shader nodes.

$\endgroup$
2
  • $\begingroup$ The 4.0 example you provided works on my end, the only change i did was to put the name of my nodegroup. Is this exactly the line of code that you use in your script? $\endgroup$
    – Lauloque
    Commented Mar 31 at 13:24
  • $\begingroup$ @L0Lock I probably should've made it more clear but NodeSocketFloat still works fine in 4.0, that was just what I used for the example. It's stuff like NodeSocketString and NodeSocketMenu that don't. But otherwise it's the same line of code. $\endgroup$
    – LuigiTKO
    Commented Mar 31 at 15:03

1 Answer 1

0
$\begingroup$

I was able to find a workaround in 4.1

Instead of using python, you can simply copy and paste a reroute node of a specific type from one node editor to another. Of course, most of them are incompatible in other node editors (even the rotation socket), but I guess the colors are cool?

enter image description here

enter image description here

enter image description here

$\endgroup$

You must log in to answer this question.

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