Jump to content

Programmatically modifying a color ramp


Memo

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?

 

 

Link to comment
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.
 
Cheers
-J
 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...