1
$\begingroup$

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?

$\endgroup$
3
$\begingroup$

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.

Color-Ramps-datablocks

| improve this answer | |
$\endgroup$
1
$\begingroup$

colorramp changed with python

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ bpy.context.scene should get the active scene $\endgroup$ – gandalf3 Oct 20 '13 at 1:27
  • $\begingroup$ Cool. Should work. At least it did here. Took me a while but it was fun to find out. $\endgroup$ – Haunt_House Oct 20 '13 at 1:34
  • $\begingroup$ 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 $\endgroup$ – gandalf3 Oct 20 '13 at 1:44
  • $\begingroup$ which OS do you have? I tested it in 2.68, works without problems. Because I get <bpy_struct, CompositorNodeValToRGB("ColorRamp")> $\endgroup$ – Haunt_House Oct 20 '13 at 1:49
  • $\begingroup$ I'm running Archlinux. (doesn't work in linux.. possible bug?) $\endgroup$ – gandalf3 Oct 20 '13 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.