3
$\begingroup$

I looked around in the source and other places and I found the code that creates a Color Ramp is as follows:

layout.template_color_ramp(tex, "color_ramp", expand=True)

Does this work for addons because I can't find any documentation or anything on it and whenever I try it doesn't draw in the panel.

I would like to use this in-panel ramp to control a color ramp that is in the Node Editor.

$\endgroup$
4
$\begingroup$

While I don't think you can add a new property to an object that can hold the colour ramp data you can display a duplicate of an existing colour ramp in your own panel if you want to. As you want to display the colour ramp that exists within the nodes of an existing material, this can be done with -

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

As the name of the colour ramp node may change you will need a way to choose which colour ramp to display, or show all colour ramps in the current material.

$\endgroup$
  • $\begingroup$ Wow! You are a life saver! :) $\endgroup$ – Nathan Craddock Nov 29 '14 at 19:11
2
$\begingroup$

The required pointer property for a color ramp data structure can't be created with Python, it needs to be done in native C code. You can then use Python to create a UI widget and store the data in that property.

$\endgroup$

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.