I need to define a colorband using python script, but I don't know how to do this in Blender 2.74. In 2.49 version has a command colorbandDiffuse but in 2.74 version I can't find out.


1 Answer 1


Cycles and Blender Internal render engines have a different Materials ecosystem. They're similar in many ways, but different on important details.

Blender Internal

import bpy

mat = bpy.data.materials.new('experiment')
mat.use_diffuse_ramp = True
elem = mat.diffuse_ramp.elements.new(0.25)
elem.color = (1,0.2,0.3,0.3)


Involves adding nodes, or appending a premade material from a different .blend (also easy but a different topic)

import bpy

mat = bpy.data.materials.new('experiment4')
mat.use_nodes = True

ramp_node = mat.node_tree.nodes.new('ShaderNodeValToRGB')
elements = ramp_node.color_ramp.elements

elem = elements.new(0.25)
elem.color = (1,0.2,0.3,0.3)

# the default 'new material' always has a 'Diffuse BSDF' node, 
# here we obtain a reference to it
diffuse_node = mat.node_tree.nodes['Diffuse BSDF']

# nodes need to be hooked up!
mat.node_tree.links.new(ramp_node.outputs[0], diffuse_node.inputs[0])

The reason I mention appending an existing material is because it can be a lot more convenient to tailor a complex material once and use many variations of it in subsequent blends by appending the material and adjusting known values. Scripting Cycles materials can be a little verbose :)

If you still have questions then hopefully you'll have some idea what to ask about.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .