Jump to content

Python - Setting ramp colour values


TomRaynor

Recommended Posts

Hi,

 

Just trying to work out how to set (colour, or I suppose spline) ramp parameter values using python.

I have sussed out the code to get the ramp positions and colour values, just not how to set them.

 

Aside:

The reason I want to do this is because I am making a quick and dirty python utility script to copy a ramp parameter's values and apply them to another ramp parameter, because as far as I know, you can't do this at the moment... I would love to be proven wrong!

 

Cheers,

Tom

Link to comment
Share on other sites

Ramps are really just fancy multiparm parameters.  Given a ramp parameter, you can access all the individual parms by calling hou.Parm.multiparmInstances().  This should give you all the position, color and interpolation parms you can then do stuff with.

 

If you are just trying to copy a ramp to another one, you can make use of a hou.Ramp object you get by evaluating a ramp parameter and just setting the other parameter with it:

>>> p1 = hou.parm('/obj/geo1/null1/parm')
>>> p1.eval()
<hou.Ramp is_color=True num_keys=2 data=((t=0, rgb=(0, 0, 0.9)), (t=1, rgb=(0.9, 0, 0)))>
>>> p2 = hou.parm('/obj/geo1/null2/parm')
>>> p2.eval()
<hou.Ramp is_color=True num_keys=2 data=((t=0, rgb=(0, 0, 0)), (t=1, rgb=(1, 1, 1)))>
>>> p2.set(p1.eval())
>>> p2.eval()
<hou.Ramp is_color=True num_keys=2 data=((t=0, rgb=(0, 0, 0.9)), (t=1, rgb=(0.9, 0, 0)))>
  • Thanks 1
Link to comment
Share on other sites

Ah amazing. I didn't realise that you could  set the second ramp parameter that simply. I was trying to get a list of values and keys for the "ramp to copy" and then somehow create and set the keys and values in the second ramp. I got stuck as I couldn't find a way to set the second ramps keys and values using python.

 

Can you set any general multiparm's values in this way then?

 

Thanks!

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...