Python API support for CurveProfile, CurveMapping, and ColorRamp

Hello everyone,

I worked on supporting the creation of CurveProfile, CurveMapping, and ColorRamp properties through the Python API. I only needed curve mapping for my personal project, but went on and added the other two as a bonus. So they are not really “stress tested”.

You can define your own properties of such types, for example:

# Define a curve mapping for a vector value, with 'X', 'Y', and 'Z' buttons in the UI.
# Other types are 'VALUE', 'HSV', and 'CRGB', which are the common curve mapping types for the UI.
my_curve_mapping: bpy.props.CurveMappingProperty(name = "My Curve Mapping", min = 0.0, max = 10.0, subtype = 'XYZ')

# Define a curve profile with the line preset, which will be used when resetting the profile in the UI.
my_curve_profile: bpy.props.CurveProfileProperty(name = "My Curve Profile", preset='LINE')

# Define a color ramp. This will be a default a default ramp with one black, and one white slider.
my_color_ramp: bpy.props.ColorRampProperty(name = "My Color Ramp")

For UI layout, you can use the usual interface templates for them (e.g. template_curve_mapping). It is not possible to use layout.prop as it would require extra parameters to display specific buttons.

There are 3 patches for them:

See there for more details. For application order, each patch depends on the previous one. A single patch for all three can be found here: ✎ P3164 Unified patch

It would be nice if addon developpers around here could try and test them, in case anything is missing, or to improve on the default settings, etc.

22 Likes

This is absolutely awesome!

1 Like

Oh that’s super awesome :slight_smile:

1 Like

This is so great, no more terrible workarounds creating unused colour ramp nodes etc. :grin:

2 Likes

so great!!
but it’s an error?


maybe
#define IDP_CurveMapping(prop) ((struct CurveMapping *)(prop)->data.pointer)

This has been missing for a while! I don’t have a ton of time to test it, but is there an ETA for this to land?

Thanks, I fixed it.

There is no ETA for this. Hopefully it can make it into the next release.

Thanks for doing this @KevinDietrich

Forgive my ignorance, does that mean these widgets can be created for node group interfaces as well ?

No, it just means that they can be created directly from the python API. Previously, you could interact with existing widgets (for example the ramp widget in a colour ramp node), but you couldn’t create your own.
With this patch, that will now be possible, which will make things a lot easier for addon devs.

3 Likes

Hi, do you know if/when this will make it into master? It seems like a clear improvement to the API to me, and it would be a shame for it to get stuck in limbo…

Thanks!

2 Likes

This is an amazing patch! Could help to solve a number of issues for addon developers. Hope it lands soon in master.

1 Like

Hi, I put this patch aside to work on other things. At last check there were a couple of areas in the code which did not handled those new properties. Also no code review officially started for that, so I can’t give an ETA.

2 Likes

Bumping this thread. Really would be helpful for addons @KevinDietrich

2 Likes

This needs to be first accepted/signed off by core members. So I’ll create a formal design task for it. If accepted, I’ll then make a pull request.

3 Likes

The design task is here #105781 - Python API support for creating CurveMapping, CurveProfile and ColorRamp properties. - blender - Blender Projects, if you want to follow along or give a thumbs up.

2 Likes

I would be happy to know if there is any progress on this.