cycles nodes adding new ones how to

is there some example on how to add new cycles nodes for a specific object?

like selet and ojbect then if no mat defined add a new mat for this object then add some new nodes setup for each material ?

i can add new cycles mat if the amt already exist in normal blender
but how to do it if the mat don’t exist on a specific object ?

thanks for any feedback

obj =['cube']
mat ='mat')
mat.use_nodes = True

While that does add a material to an object, it has no output node. How do you add an output node to a material?

While that does add a material to an object, it has no output node. How do you add an output node to a material?
I’m not sure what you mean. It adds (by default) a diffuse shader and a material output.

@RickyBlender: As far as I’ve seen, it works the same as the nodes in Blender Render mode.

where can i find the values name for the different nodes ?


RGB color RGB fact
Math values Math function like add multiply ect
Mapping location x y z scale X y Z

dont’ knwo what names i have to use

i think i have the one for RGB color

Add color to shaders

This sets the colors


but don’t have the other ones !

whre do you find these name in API doc PDF ?


Math node function: mathnode.operation
Mapping node: mapnode.location, mapnode.rotation, mapnode.scale

I reading this from the console using autocomplete

how do you get that from console ?
can you do a dir of something ?

is there a way to give a name to a node
like instead of RGB call it RGB#1?


After running the code on the default cube and clicking on the material I see this.


@RickyBlender: I just use autocomplete and see what comes up.
To name a node you just: = ‘RGB#1’. You can then use this as the name instead of ‘RGB’.

@Atom: I can’t get it to do that. What version are you using?
Anyway, to add a output node, you:‘OUTPUT_MATERIAL’). That will give you a material output and you just link that to a diffuse, glossy, etc.

problem is that i have something like 1000 lines of codes
i cannot enter 1000 lines in console to get doc to the one i’m doing!

so is there another way inside the script to get it where i’m located !
where i don’t need to enter lots of lines in console !

for atom problem i can see one problem i have too
right now i use the master list of mat
not the object list of mat

so is there a simple example showing how to use the object list of mat to add node

or if using the master list then how to get the mat name from object mat list and apply with a if in the master list loop may be!


here is example of what i got using the master mat list

sorry i added the wrong little snippet here
so i replaced it with a simple example

i tried the dir name inside sc ript like show near the end
and it does not print anything !

#  Weave diagonales  lines
import bpy
from bpy.props import *
from mathutils import *
from math import *
row1 =400
col1 =500
print ()
print ('Weave diagonales  lines')
print ()
print ('Render engine =',bpy.context.scene.render.engine)
if bpy.context.scene.render.engine=='BLENDER_RENDER':
 print ('Render is = BLENDER_RENDER')
 print ('Converted to BLENDER_CYCLES')
 print ('Render is = CYCLES')
print ()
['__bool__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__doc__', '__getattribute__',
'__getitem__', '__iter__', '__len__', '__module__', '__setattr__', '__setitem__', '__slots__', 'bl_rna',
'find', 'foreach_get', 'foreach_set', 'get', 'is_updated', 'items', 'keys', 'new', 'remove', 'rna_type',
'tag', 'values']
mats =
sc = bpy.context.scene
for cmat in mats:
 print (' cmat =',cmat)
 links = TreeNodes.links
# print (' mat=',len(mats))
# print (' mat=',len(mats),' name =',
# ShaderNode(Node)         Page 949
 print ()
 for n1 in TreeNodes.nodes:
  if n1.type == 'OUTPUT_MATERIAL':
   if n1.label == 'Lock':
    print (' being lock')
 if lock:
   for n2 in TreeNodes.nodes:
   if not shader :
    # Material node
    shout ='OUTPUT_MATERIAL')   # This add a new material output node
    shout.location = col1,row1        
    # Diffuse shader node
    shaderdiff1 ='BSDF_DIFFUSE')  # This add a new BSDF_DIFFUSE node  
    shaderdiff1.location =col1-400, row1
#    shaderdiff1.operation =" "
    # Glossy shader node
    shadergloss1 ='BSDF_GLOSSY')  # This add a new BSDF_GLOSSY node  
    shadergloss1.location = col1-400, row1-200
    # Mix shader node
    shadermix1 ='MIX_SHADER')   # This add a new MIX_SHADER node  
    shadermix1.location = col1-200, row1 = "Mix1"[0],shout.inputs[0])[0],shadermix1.inputs[1])[0],shadermix1.inputs[2])
 # MIX_RGB node
    shaderMIX_RGB1 ='MIX_RGB')     # This add a MIX_RGB node  
    shaderMIX_RGB1.location = col1-600, row1+100
#    shaderMIX_RGB1.operation="MULTIPLY"
 # Add color to shaders
                 # This sets the colors
   if shaderdiff1.type=='BSDF_DIFFUSE':
#    shader.inputs['Roughness'].default_value=cmat.specular_intensity  
    shaderdiff1.inputs['Roughness'].default_value=0.3333   # This sets the value of the BSDF_DIFFUSE

problem is that this is adding nodes to all mat in master mat list !
which is not what i want !

now how do you change this for using object’s list of mat ?

here is sample file

znodecyclesimple1.blend (412 KB)


i got some help with dir inside the script
like this

print (’ shaderMIX_RGB1 =’,dir(shaderMIX_RGB1))

and on console i get

shaderMIX_RGB1 = [‘doc’, ‘module’, ‘slots’, ‘bl_rna’, ‘blend_type’
, ‘inputs’, ‘label’, ‘location’, ‘name’, ‘outputs’, ‘parent’, ‘rna_type’, ‘show_
texture’, ‘type’, ‘use_alpha’]

which gives all the attributes i guess

now how to set the value for the FAC

tried this


but gives error !

i did find the open for blend type

this value FAC does not seems tobe shown in dir doc
anyway to show it ?


mix.inputs[‘Fac’].default_value = 0.3333 works. If you enter mix.inputs in the console, then press CTRL+SPACE, it sohuld give you the names of all the inputs for that node.

i tried with fac then with FAC but did not try it with Fac!

can we get the help from the dir function inside teh script
i tried the get it with dir but nothing on this Fac thing!

Now how can i apply this to one material instead of all the mat list !


I don’t get what you’re asking. The example I gave is for one material.

you mean that one

obj =[‘cube’]
mat =‘mat’)
mat.use_nodes = True

i could select one object and then enable nodes then add cycles nodes to this mat!

but i want to add or replace cycles nodes for one specific mat on a selected object

and i think i found a problem

if the object does not have any normal mat not a cycle mat one it does not work!

so i need to make a test to see first if there is a normal blender material
then add one if no mat then after that i guess it is possible to add cycles nodes!

i think this way it should work

i want to make sort of menu where you select one object and one material then
the script would add a specific cycles nodes set up

if you want to have a cycle material type Old brass
then this would help to get the nodes set up in cycles for this old brass mat !

i already made a 2 levels menu for the cycles mat panel
now i got to add function to add cycle nodes to a specific material on a selected object !

with that i hope to get a minimum lib of nodes set up in cycles mat for objects
at least it would make it easier and faster to get basic cycles material nodes set up

and may be include some light set up for cycles too!


did a test whit little code

obj =[‘cube’]
mat =‘mat’)
mat.use_nodes = True

now this seems strangely to add 2 materials
one is empty and then there is the new material “mat”

now if you do that this is adding a node material in blender not cycle
and you cannot add a cycles mat to this manually !

need to set cycles render before like this

 import bpy
obj =['Cube']
mat ='mat')
print ('Render engine =',bpy.context.scene.render.engine)
if bpy.context.scene.render.engine=='BLENDER_RENDER':
 print ('Render is = BLENDER_RENDER')
 print ('Converted to BLENDER_CYCLES')
 print ('Render is = CYCLES')
print ()
mat.use_nodes = True

like this it will add the default node set up diffuse and out material in cycles!


if i use the little snippet for specific object and a specific mat

how can you use nodetree to add or replace node setup for a material in cycles ?

obj =[‘Cube’]
mat =‘mat’)

i did not find any other example yet for this
would be nice to see anything on how to do this