Battling with a script to create specified number of color entries in a 2d ramp

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  03 March 2011
Battling with a script to create specified number of color entries in a 2d ramp

Hey guys.

I am a real newbie at scripting so excuse my stupidity. But basically I'm trying to create a script that creates a 2d ramp texture with a specified amount of color entries all evenly spaced.

So running the script with say a specified value of 300, would create a ramp texture with 300 colors , all evenly spaced (1/300 etc).

at the moment my script looks like this..

createNode ramp -n "rampSpecial"

int $i;
for ($i = 0; $i<300; $i++) {
float $d = 1/300;
for ($d = 0; $d<1; $d++) {

setAttr ("rampSpecial"+".colorEntryList["+$i+"]"+".position"+$d+);


I'm currently getting a syntax error with the last line.
What I'm trying to do here is input an integer that counts from 1 to 300 in place of the colorEntryList value, and then the $d is my attempt at trying to evenly space the color entry values by inputting it into the ".position" input.

I'm not even sure if it's only my syntax that is wrong or whether its the way I'm trying to create more color entries which is incorrect aswell.

As you can tell I'm pretty clueless and I'm sure it may make some of you /ignore this post completely . But I would very much appreciate some help here, I know this is probably a really simple script to make.


Last edited by LinchpinZA : 03 March 2011 at 05:11 PM.
  03 March 2011
You are missing a } at the end. You also seem to be adding ..... ?
setAttr ("rampSpecial"+".colorEntryList["+$i+"]"+".position" + $d + );

Personally I don't much care for the style of

for () {

You'll have less problems of this sort using:

for ()

just my 2cents...


this might be a nice thing to do:

setAttr -size 300 ("rampSpecial"+".colorEntryList);

and in addition, not sure what you are doing with $d? Should be 2 variables perhaps?

float $d = 1/300;
for ($d = 0; $d<1; $d++) {

Last edited by Robert Bateman : 03 March 2011 at 05:32 PM.
  03 March 2011
Hey Robert,
Thanks for the reply and the helpful tips. I've had another attempt at the script after your post and doing some more reading.

Quote: You are missing a } at the end. You also seem to be adding ..... ?
setAttr ("rampSpecial"+".colorEntryList["+$i+"]"+".position" + $d +);

Yeah over here I was trying to make the "colorEntryList" create more entries counting up in integers
to the specified maximum value of 300. And then I wanted each of these new entries to be evenly spaced along the ramp, so the final result would be 300 colors on a ramp with 299 equal spaces between each color. But as you can tell I failed

With $d I was trying to divide 1 by 300, to give me a float value for the spacings between the colors on the ramp. I then wanted to add this float value to each respective colorEntry's position to space out the 300 colors evenly. I know now that I was supposed to convert the numbers to floats to give me a float output and also divide by 299 instead...float $d = (float (1) /float (299));

Also I tried this like you said after creating a node called rampSpecial..
Quote: setAttr -size 300 ("rampSpecial"+".colorEntryList");

Maya ran that line fine with no complaints but it didn't create 300 color entries. The ramp remained remains the same with it's default 3 inputs.

I thought I should start with something simpler.. making a ramp with 6 colors spaced randomly and then trying to space these color entries evenly along the ramp into 5 equal divisions using a mel script.
I know the steps would be:
-list each color entry,
-for each consecutive entry add 0.2 to the position value.

so it gives me a result like ..

"rampSpecial.colorEntryList[0].position" 0;
"rampSpecial.colorEntryList[1].position" 0.2;
"rampSpecial.colorEntryList[2].position" 0.4;
"rampSpecial.colorEntryList[3].position" 0.6;
"rampSpecial.colorEntryList[4].position" 0.8;
"rampSpecial.colorEntryList[5].position" 1;

I know that using
int &i;
for ($i = 0; $i<6; $i++) {

creates a variable $i that counts up.

and that this bit of script
float $c = (float (1) /float (5));

would give me an output of 0.2 , but in the end I would need to ++ add this value to each consecutive colorEntry's position. How do I do this?

Any further help would be greatly appreciated

Last edited by LinchpinZA : 03 March 2011 at 09:40 PM.
  03 March 2011
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 10:45 AM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.