1
$\begingroup$

I am having difficulty creating a link using the new method of creating sockets in Blender 4.0's python api. More details on the changes here, while it doesn't cover links or the issues I'm having: https://wiki.blender.org/wiki/Reference/Release_Notes/4.0/Python_API

My question is: How do we access the "NodeSocket" type needed to create links from the "NodeTreeInterfaceSocketType"?

Error message from example code below:

Error:
TypeError: NodeLinks.new(): error with argument 1, "input" -  Function.input expected
a NodeSocket type, not NodeTreeInterfaceSocketFloat

Example Code:

group = bpy.data.node_groups.new("group_name", type='ShaderNodeTree')
nodes = group.nodes
links = group.links    
input_node= nodes.new(type='NodeGroupInput')
#Example math node to link to
math_node = nodes.new(type='ShaderNodeMath')
Input_1 = group.interface.new_socket(name='Input Name', in_out='INPUT', socket_type='NodeSocketFloat',)
links.new(Input_1,math_node.inputs[0])
$\endgroup$

1 Answer 1

2
$\begingroup$

The new interface API is for only node tree sockets not for node sockets. When you create one it is already in NodeGroupInput.

import bpy

group = bpy.data.node_groups.new("group_name", type='ShaderNodeTree')
nodes = group.nodes
links = group.links

input_node= nodes.new(type='NodeGroupInput')

math_node = nodes.new(type='ShaderNodeMath')

Input_1 = group.interface.new_socket(name='Input Name', in_out='INPUT', socket_type='NodeSocketFloat')

links.new(input_node.outputs[0], math_node.inputs[0])

NodeGroupInput is a node inside ShaderNodeTree that exposes the node tree input socket that you create with interface.new_socket.

ShaderNodeTree interface inputs are the outputs of the NodeGroupInput inside it.

$\endgroup$

You must log in to answer this question.

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