Page MenuHome

Unable to create group input/output sockets with python
Closed, InvalidPublic

Description

System Information
FreeBSD 9.2 amd64 Nvidia gt520

Blender Version
Broken: Blender 2.69
Worked: Blender 2.66

Short description of error
Using python I can create a group and add group input and output nodes but I can't add sockets to these nodes to connect anything to. I can create and connect other nodes within the group.

Exact steps for others to reproduce the error
In 2.66 the following script works, it creates a group, adds a node and connects the node to the group in/out sockets.

test_group = bpy.data.node_groups.new('testGroup', 'SHADER')
test_group.inputs.new('in_to_nodes','VALUE')
test_group.outputs.new('out_result','VALUE')

node_add = test_group.nodes.new('MATH')
test_group.links.new(test_group.inputs[0], node_add.inputs[0])
test_group.links.new(node_add.outputs[0], test_group.outputs[0])

From 2.67 node groups started to be edited over the top of the nodes display, this introduced group input and output nodes. This would mean the script would be changed to

test_group = bpy.data.node_groups.new('testGroup', 'ShaderNodeTree')

group_inputs = test_group.nodes.new('NodeGroupInput')

group_outputs = test_group.nodes.new('NodeGroupOutput')

node_add = test_group.nodes.new('ShaderNodeMath')
node_add.operation = 'ADD'

While that much works in python I can't get a new input or output socket created to make connections.

I expect group_inputs.outputs.new() to be the way to do this but it fails without error.

group_inputs.inputs.new() does create sockets but on the wrong side showing an error - Undefined Socket Type

Manually created sockets appear to be available in test_group.inputs but test_group.inputs.new() also fails without error.

There is an operator bpy.ops.node.tree_socket_add() that will create sockets but it is only available when a node editor is in context.

Details

Type
Bug

Event Timeline

Shane Ambler (sambler) set Type to Bug.
Shane Ambler (sambler) created this task.
Shane Ambler (sambler) raised the priority of this task from to Needs Triage by Developer.
Shane Ambler (sambler) closed this task as Invalid.Dec 11 2013, 11:55 AM
Shane Ambler (sambler) claimed this task.

We found the missing link, use NodeSocketFloat instead of VALUE for group.inputs.new()

test_group.inputs.new('NodeSocketFloat','grpInput')
test_group.outputs.new('NodeSocketFloat','grpOutput')

Though it would be helpful if inputs.new('VALUE','grpInput') provided some sort of error.