0
$\begingroup$

So I'm trying to write code that creates a custom set of Nodes for the ShaderEditor. Code:

import bpy

def create_custom_node_group(self, context):

    node_tree = bpy.data.node_groups.new('custom group', 'ShaderNodeTree')
    node_tree.inputs.new('NodeSocketColor', 'Color')
    node_tree.outputs.new('NodeSocketColor', 'Output')

    group_in = node_tree.nodes.new('NodeGroupInput')
    group_in.location = (-200, 0)

    group_out = node_tree.nodes.new('NodeGroupOutput')
    group_out.location = (200, 0)
    
    mix_node = node_tree.nodes.new(type= 'ShaderNodeMixRGB')
    mix_node.location = (0, 0)
    mix_node.inputs[0].default_vaule = 0.6
    mix_node.inputs[7].default_vaule = (0, 1, 0, 1)

    link = node_tree.links.new

    link(group_in.outputs[0], mix_node.inputs[6])
    link(mix_node.outputs[0], group_out.inputs[0])

    return node_tree

class NODE_OT_test(bpy.types.Operator):
     bl_label = "Test"
     bl_idname = "node.test_operator"

     def execute(self, context):
          group = create_custom_node_group(context)

          context.active_object.active_material.use_nodes = True

          node = context.active_object.active_material.node_tree.nodes.new('ShaderNodeGroup')
          node.node_tree = bpy.data.node_groups[node_name]
          node.use_custom_color = True
          node.color = (0.5, 0.4, 0.7)

          return {'FINISHED'}

The thing is, when I try to run the script, I get the following error: AttributeError: 'ShaderNodeTree' object has no attribute 'inputs'

I would love to get help.

(Some code typo are possible, it's because I changed all the names of the methods and such when I copied the code)

$\endgroup$
3

0

Browse other questions tagged .