Jump to content

Programmatically modifying a color ramp

Recommended Posts

Is it possible to programmatically modify a color ramp via python (add / remove / edit keys,values, basis etc)? All I've found is this http://www.sidefx.com/docs/houdini13.0/hom/hou/Ramp which only explains how to read these values, not write to them. 


The reason I'd like to do this is:

I have VEX code which colors my particles based on a number of color ramps. That all works fine. However editing the color ramps can be cumbersome, and I already have color palettes created in photoshop which I'd like to use. I thought my options are:


1. Hand edit the color ramps to reflect the color palettes. Very boring and tedious.

2. Hand enter the RGB values into VEX. Even more boring and retarded.

3. Write a tool which loads the palettes in whatever format, and modifies a color ramp to reflect the palette. The VEX code just references this color ramp. This code would only execute once obviously, I load my palette and bang, the color ramp is up to date. I loved this idea, because I could scatter a bunch of these nodes around, each one a different palette, and the VEX code just references a different node for a different palette. 


However I can't find how to modify the color ramp so I'm stuck. My plan B is to output the RGB values to number box arrays, and have VEX reference that, which might be faster anyway, but I lose the in between values and the ability to visually tweak the palette in context. Any ideas?



Share this post

Link to post
Share on other sites

Is this what you want ??


myNode                                                        #  your node with the ramp parameter


attnParm = myNode.parm('attenramp')        # Get the ramp parameter 


attnParm.set(5)                                            # You can add more points to the ramp just by setting the number you want.  


You can also get the keys and iterate over them and set the value on all ramp parms


rampKeys = attnParm.eval().keys()              # Get the keys 

numPoints = len(rampKeys)                         # Get the number of points 
for keyNum in range(1, numPoints + 1):
        posParm = myNode.parm('attenramp + str(keyNum) + 'pos')
        posParm.set(your value)
Similarly you can iterate through other ramp params like color and interpolation and set them accordingly.
Hope this helps.

Share this post

Link to post
Share on other sites

why shiver me timbers that worked! thanks. Can I ask how and where you found this info? I searched all the docs but couldn't find anywhere that you could do this. 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now