I've seen this post from 9 years ago and I'm asking it again because is possible that things have changed (I hope) when it comes to work with color ramps.

I'd like to display and modify a color ramp inside my addon's menu.

According to that post, we have to retrieve a color ramp node from some kind of node based object, like a material:

cr_node = bpy.data.materials['Material'].node_tree.nodes['Color Ramp']
layout.template_color_ramp(cr_node, "color_ramp", expand=True)

Just added a little correction to the original code ("ColorRamp" to "Color Ramp" to match the default name).

This is showing correctly in my menu:

enter image description here

Even though, when I try to edit it, it crashes Blender.

enter image description here

(I'm making no further work with the Color Ramp inside my code, at the moment I'm just displaying and editing it).

More info:

  • The menu I'm displaying it is in the Operators Undo menu (I think is called (those temporary windows that appear after executing an operator))

So my question is; is it possible to display and modify a color ramp? This (old hacky) approach is still "valid" or is there a better way to work with color ramps?

Thank you so much for the help.

  • $\begingroup$ I've no idea whether you can use this method with python, but you can use drivers to control both the colour and slider positions of a Color Ramp. There's a YT tutorial from Ryan King detailing how to do it here. $\endgroup$
    – John Eason
    Feb 5 at 11:22
  • 1
    $\begingroup$ My guess is the crash is caused from modifying using the undo panel try setting it up in a normal panel. $\endgroup$
    – Ratt
    Feb 5 at 11:25
  • $\begingroup$ @JohnEason Just saw the video, didn't know that! Thanks for the idea mate :) $\endgroup$
    – Ommadawn
    Feb 5 at 21:33
  • $\begingroup$ @Ratt Indeed, I tried in a normal panel and do not crash :). it's a bit inconvenient to have those properties separated but I guess we don't have an option. Thanks for the help mate :) $\endgroup$
    – Ommadawn
    Feb 5 at 21:35
  • 1
    $\begingroup$ @Ommadawn There are likely several scenarios when the 'undo panel' should not be used but consider the fact that in this instance dragging a slider a couple pixels across the screen causes the thousands of operations both restoring the previous state and calculating the new state. When changing an integer value with a small range 0-10 etc. there are far fewer calculations made but still one to revert to a previous state and one to perform the 'operation' with the new value. Using a normal panel you can instead force updates only on setting a value not changing it. $\endgroup$
    – Ratt
    Feb 5 at 22:24


You must log in to answer this question.

Browse other questions tagged .