2
$\begingroup$

I have this code:

import bpy
import random

max_number = 5
nodes = []
with_fade_out = 2



try: 
    tree = bpy.context.scene.node_tree
except:
    bpy.context.scene.use_nodes = True



group = bpy.data.node_groups.new(type="CompositorNodeTree", name="MultipleSwitch")
group.inputs.new("NodeSocketRGBA", "Default Image")

for i in range(0,max_number):
    group.inputs.new("NodeSocketRGBA", ("Variation - " + str(i+1)))



input_node = group.nodes.new("NodeGroupInput")
input_node.location = (-150, 0)

group.outputs.new("NodeSocketRGBA", "Out")
output_node = group.nodes.new("NodeGroupOutput")
output_node.location = (max_number*100 + 100, 0)


group_node = tree.nodes.new("CompositorNodeGroup")

group_node.node_tree = group

But When I Run this script, It doesn't show upo any input or output, but if I put NodeSocketFloat instead of NodeSocketRGBA, it show up all the input.

$\endgroup$
1
$\begingroup$

For example, using the bpy docs, see the base classes (names of the valid socket ID names).

import bpy
import random

max_number = 5
nodes = []
with_fade_out = 2

try: 
    tree = bpy.context.scene.node_tree
except:
    bpy.context.scene.use_nodes = True

group = bpy.data.node_groups.new(type="CompositorNodeTree", name="MultipleSwitch")
group.inputs.new("NodeSocketRGBA", "Default Image")

for i in range(0,max_number):
    group.inputs.new("NodeSocketRGBA", ("Variation - " + str(i+1)))

input_node = group.nodes.new("NodeGroupInput")
input_node.location = (-150, 0)

socket_list = [
    'NodeSocketBool', 'NodeSocketColor', 'NodeSocketFloat',
    'NodeSocketFloatAngle', 'NodeSocketFloatFactor', 'NodeSocketFloatPercentage',
    'NodeSocketFloatTime', 'NodeSocketFloatUnsigned', 'NodeSocketInt',
    'NodeSocketIntFactor', 'NodeSocketIntPercentage', 'NodeSocketIntUnsigned',
    'NodeSocketShader', 'NodeSocketString', 'NodeSocketVector',
    'NodeSocketVectorAcceleration', 'NodeSocketVectorDirection',
    'NodeSocketVectorEuler', 'NodeSocketVectorTranslation', 'NodeSocketVectorVelocity',
    'NodeSocketVectorXYZ', 'NodeSocketVirtual']

for s in socket_list:
    group.outputs.new(s, "Out " + s)

output_node = group.nodes.new("NodeGroupOutput")
output_node.location = (max_number*100 + 100, 0)
group_node = tree.nodes.new("CompositorNodeGroup")
group_node.node_tree = group

enter image description here

you can see here that of all those NodeSocket types, the main ones are:

NodeSocketBool
NodeSocketColor
NodeSocketFloat
NodeSocketInt
NodeSocketShader
NodeSocketString
NodeSocketVector
| improve this answer | |
$\endgroup$

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.