Changing an rbg input color via script

I am trying to change the value of an rbg node through a script. I made the change in the GUI and basically just copied the command from the python console. This is the line of code I am trying, which throws this error: 2.69 . Thanks in advance,[“Shader Nodetree”].nodes[“RGB”].outputs[0].default_value = (0.00402498, 0.0794195, 0.251406, 1)

Key “Shader Nodetree” not found

got a basic example how to get ob mat and then add a new mat nodes for cycles
but not for editing existing one
but if you have the mat then should be easy to edit one

import bpy
from bpy.props import *
from mathutils import *
from math import *
node_gap = -200.0
if bpy.context.scene.render.engine=='BLENDER_RENDER':    # Select renderer
 print ('Render is = BLENDER_RENDER')
 print ('Converted to BLENDER_CYCLES')
 print ('Render is = CYCLES')
mats =
print (' Material count =',len(mats))
sc = bpy.context.scene
obj_sel = bpy.context.selected_objects
if len(obj_sel) > 0:
 sel_obj_name_list = []
 for ob in obj_sel:
  if ob.type == "MESH":
 print (len(sel_obj_name_list), sel_obj_name_list)
 print ("Nothing selected")
lock=True # What's this??
shader='' #.. and this? FOR cycle gets never ended, making myrriads of nodes... Funny.
def initmat1(obj):
 context = bpy.context
 # fetch active_object
# obj = context.active_object
 if not obj:
  pring("WARNING: no active_object")
 if obj.type != 'MESH':
  print("WARNING: active_object is no mesh object")
 # fetch/create/assign material
 mat_name = "Material"
 mat =
 if not mat:
  print("WARNING: active_object don't have material assigned")
  # try to get existing global material
  mat = context.blend_data.materials.get(mat_name)
  if not mat:
   print("WARNING: material does not exists")
   # try to create new global material
   mat =
   if not mat:
    print("ERROR: creating new material finally not succeeded",
   print("INFO: created new material (real created material name/key is:'{}')".format(
  # append material to object
obj = bpy.context.active_object
print (' mat name =',
mat_name = "Material"
mat =
mat.use_nodes = True
print (' mat  name =',mat_name)
links = mat.node_tree.links
# This will add some new nodes to a new material
           # remove all default nodes
## Creates nodes  output  Textimage  Text cord
node0 ='ShaderNodeOutputMaterial')     # Add Output material node
node0.location = (0.0, 0.0)
node1 ='ShaderNodeMixShader')      # Add mix  node
node1.location = (node0.location.x+node_gap, 0.0)
node2 ='ShaderNodeBsdfGlass')      # Add Glass  node
node2.location = (node1.location.x+node_gap, -node_gap/2)
node3 ='ShaderNodeBsdfTransparent')     # Add Transp  node
node3.location = (node1.location.x+node_gap, node1.location.y+node_gap/2)
node4 ='ShaderNodeBrightContrast')     # Add Bright Contrast  node
node4.location = (node2.location.x+node_gap, node2.location.y-node_gap/2)
# Makes links
link1_0 =['Shader'], node0.inputs[0])
link2_0 =[0], node1.inputs[0])
link2_1 =[0], node1.inputs[2])
link4_0 =[0], node2.inputs[0])
# Default values
#node1.inputs[0].default_value = (1.0, 0, 0, 1/.0)    # Diff. color

happy cycles

Thank you Ricky, I got it working these are the lines of code I used to change the rgb value of a rbg node. The material shows up 4th in my materials list so it’s index is 3. Note that this for a material and an rgb node that already exists (through the GUI in this case)

mymat =[3]  
rgb_node = mymat.node_tree.nodes["RGB"].outputs[0].default_value = (1,0,0,1)

This changes it to red, I am guessing the last parameter is alpha.

Again thanks, Ricky

Happy 2.69!