← All ideas
  • Published 18 Apr 2018

Make it possible to create ColorRamp from Python

This is a feature request to make the ColorRamp available from Python.

Currently it is only possible to embed an existing ColorRamp into a custom UI . However it is not possible to create a new ColorRamp from Python, this can only be done in C code.

One workaround is to use an existing ColorRamp, e.g. in a Cycles node, however this workaround has drawbacks and is hacky. Another workaround is to add textures which have an embedded ColorRamp, but this obviously clutters the texture list with helper textures.

88.9%

Development Status: Open

Upvote 8 Downvote 1
simonwendsche
18 Apr 2018

5 Comments

bblanimation

bump this would be a very useful feature. Here's an example (bare bones, mind you) of how a custom ColorRamp node would be added (the most relevant portion to this feature request is the 'color_ramp' class variable and the 'draw_buttons' class method).

class ColorRampNode(CustomNode):
    bl_idname = "myaddon_ColorRampNode"
    bl_label = "Color Ramp"

    ###################################################
    # class variables

   color_ramp = PointerProperty(
        type=bpy.types.ColorRamp,
    )

    ################################################
    # initialization method

    def init(self, context):
        self.inputs.new("CustomNodeSocketColor", "Image")
        self.outputs.new("CustomNodeSocketColor", "Image")

    #############################################
    # class methods

    def draw_buttons(self, context, layout):
        layout.template_color_ramp(self, "color_ramp", expand=False)

    ################################################
jason

You're going to have to be more specific here. Color ramps are already accessible all over Blender's interface, including in Python. What, specifically, are you looking to have added?

simonwendsche Author

@Jason van Gumster: They are accessible, but we can't create new ones, e.g. to attach to custom nodes. I updated the description to make it more clear.

1
jason

@simonwendsche: This is definitely more clear. Though I'd like to see example code that shows how you envision the API to look.

Also, how will the ramps be stored in the .blend file? Currently, they aren't datablocks. Would you be looking to set them up like that, or would they be stored some other way?

simonwendsche Author

@Jason van Gumster: To be honest, I currently have no idea how exactly this would be implemented. This would require a look from an experienced Blender developer. I just wanted to log this issue as a feature request. Maybe in a few years we will have it available... I am developing addons for external renderer integration, so I'm used to this and have a lot of patience.

Another option for me would be to allow OpenGL drawing with bgl/blf in the user interface, like Campbell Barton did in this patch that was sadly never merged: youtube.com/watch But I should probably submit that as a separate request.