3
$\begingroup$

How can I set the output socket type of a nodegroup output socket from python?

I don't even know of any good way to do this in the UI.. The only way I know of in the UI is to connect a node output of the type I want (e.g. a yellow color output) to the Group Output node.

I tried setting socket.type, however there is no error message and the socket type does not change.

This is important because the default is a 'VALUE' socket, which converts colors into grayscale.

Here is the relevant part of my script:

main_group = bpy.data.node_groups.new(type="ShaderNodeTree", name="Object Color")
main_group.outputs.new("NodeSocketFloat", "Object Color")
output_node = main_group.nodes.new("NodeGroupOutput")
output_node.location = (600, 0)
output_node.inputs["Object Color"].type = 'RGBA'
$\endgroup$
5
$\begingroup$

You define the type when you create the socket with new() Looking at the list on the bpy.types page there are several starting with NodeSocket that can be used.

The variations of each type alter the visual display - eg. FloatPercent shows % with the value.

NodeSocketBool
NodeSocketColor
NodeSocketFloat
NodeSocketFloatAngle
NodeSocketFloatFactor
NodeSocketFloatPercentage
NodeSocketFloatTime
NodeSocketFloatUnsigned
NodeSocketInt
NodeSocketIntFactor
NodeSocketIntPercentage
NodeSocketIntUnsigned
NodeSocketShader
NodeSocketString
NodeSocketVector
NodeSocketVectorAcceleration
NodeSocketVectorDirection
NodeSocketVectorEuler
NodeSocketVectorTranslation
NodeSocketVectorVelocity
NodeSocketVectorXYZ
$\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.