Is there a way to snap color ramp stops to equal distances?

Is there a way to snap stops in the Color ramp node to equal distances from each other?

For example, when you add a new stop by pressing the Add button, the new stop is added halfway between the selected stop and the stop to the left, but this doesn't allow for equally aligning 4 stops.

You actually could align four stops, by doing something like adding a stop in the middle, then adding stops in between the ends and the middle stop, then adding stops in between those stops and the middle stop, etc. However, this quickly gets complicated.

Is there a simple way to align stops evenly?

Set the Outliner display mode to Datablocks. Locations and colors for color ramps are in Materials → Material → node Tree → ShaderNodeTree → Nodes → ColorRamp → ColorRamp → ColorRamp → Elements → ColorRampElement

This gives you access to position and color values. Key frameable as well.

While this is probably bad python, I post it anyway until something better comes along

If it's a compositor node

import bpy
colramp = bpy.context.scene.node_tree.nodes.active # get the active node
total = len(colramp.color_ramp.elements) # how many colors are in the ramp?
c = 0.0 # first stop
step = 1.0 / (total - 1) # define the spacing according to the total number of elements
for e in colramp.color_ramp.elements: # iterate through the elements
e.position = c
c += step


If it's a material node

import bpy
mat = bpy.data.materials['Material'] # Put the name of your material here
colramp = mat.node_tree.nodes.active # get the active node
total = len(colramp.color_ramp.elements) # how many colors are in the ramp?
c = 0.0 # first stop
step = 1.0 / (total - 1) # define the spacing according to the total number of elements
for e in colramp.color_ramp.elements: # iterate through the elements
e.position = c # position is
c += step


The colorramp in question has to be selected.

• bpy.context.scene should get the active scene – gandalf3 Oct 20 '13 at 1:27
• Cool. Should work. At least it did here. Took me a while but it was fun to find out. – Haunt_House Oct 20 '13 at 1:34
• I get an error, line 3, in <module> AttributeError: 'NoneType' object has no attribute 'color_ramp' The color ramp node is selected. Running print (bpy.context.scene.node_tree.nodes.active) in the console returns None – gandalf3 Oct 20 '13 at 1:44
• which OS do you have? I tested it in 2.68, works without problems. Because I get <bpy_struct, CompositorNodeValToRGB("ColorRamp")> – Haunt_House Oct 20 '13 at 1:49
• I'm running Archlinux. (doesn't work in linux.. possible bug?) – gandalf3 Oct 20 '13 at 1:55