Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Maya® / MEL / Creating Multiple colorSliderGrp?
  RSS 2.0 ATOM  

Creating Multiple colorSliderGrp?
Rate this thread
 
63157
 
Permlink of this thread  
avatar
  • R*
  • Posted: 29 December 2011 04:30 AM
  • Total Posts: 10
  • Joined: 29 December 2011 04:20 AM

Hey

I have a scene with a small fish, a large fish and a shark. I want to create 3 controls to let the user change the colour of the shark and fishes. The controls work perfectly when I try them one at a time but if i was to highlight more than one, i would get an error saying “Object’s name ‘sliderA’ is not unique”.

So i change the last line of the “Small_Fish1_M.color” to “sliderB”. I can execute both controls without an error code but then the control for the small fish controls the shark and the shark control doesn’t work at all.

I’m ignoring the third control for now until i can get two working at the same time but ultimately i want three controls to work at the same time.

here is my code so far (I’ve left out the window controls):

setAttr "Shark_M.color"

string $shader "Shark_M"// The shader to be controlled by the slider
string $changeColor "float $curColor[] = `colorSliderGrp -q -rgbValue sliderA`;setAttr " + ($shader) + ".color -type double3 $curColor[0] $curColor[1] $curColor[2];";
colorSliderGrp -label "Shark Colour" -rgb 1 1 1 -cc "eval ($changeColor)sliderA;

setAttr "Small_Fish1_M.color"

string $shader "Small_Fish1_M"// The shader to be controlled by the slider
string $changeColor "float $curColor[] = `colorSliderGrp -q -rgbValue sliderA`;setAttr " + ($shader) + ".color -type double3 $curColor[0] $curColor[1] $curColor[2];";
colorSliderGrp -label "Small Fish Colour" -rgb 1 1 1 -cc "eval ($changeColor)sliderA;

setAttr "Large_Fish_M.color"

string $shader "Large_Fish_M"// The shader to be controlled by the slider
string $changeColor "float $curColor[] = `colorSliderGrp -q -rgbValue sliderA`;setAttr " + ($shader) + ".color -type double3 $curColor[0] $curColor[1] $curColor[2];";
colorSliderGrp -label "Large Fish Colour" -rgb 1 1 1 -cc "eval ($changeColor)sliderA;


Replies: 0
avatar

The last parameter on colorSliderGrp is supposed to be the name of the slider. I noted that you have all three sliders named SliderA. I don’t think that is right.

<* Wes *>



Replies: 1
/img/forum/dark/default_avatar.png

That’s right. I did change the last line of the setAttr “Small_Fish1_M.color” to sliderB so it looks like this:

setAttr “Small_Fish1_M.color”
string $shader 
“Small_Fish1_M”// The shader to be controlled by the slider
string $changeColor “float $curColor[] = `colorSliderGrp -q -rgbValue sliderA`;setAttr “ + ($shader) + .color -type double3 $curColor[0] $curColor[1] $curColor[2];;
colorSliderGrp -label “Small Fish Colour” -rgb 1 1 1 -cc “eval ($changeColor)” sliderB;

This screws up the controls even though i can execute it without an error. Uni deadline is 10th Jan and i’ve no idea how to fix this.

I’ve just checked again with these changes and the colour slider for the shark controls the fish and the colour slider for the fish doesn’t work at all. Is there a specific title that you have to rename it as or can it be sliderA, sliderB, sliderC etc.

Author: R*

Replied: 30 December 2011 12:37 AM  
avatar

I am hobbled a little testing this because I would have to build some sort of scene from scratch to test it. But I think you just have an incomplete renaming job from when you copied the first example to the second.

Look at these two lines (not consecutive) from your most recent post:

string $changeColor "float $curColor[] = `colorSliderGrp -q -rgbValue sliderA`;setAttr " + ($shader

colorSliderGrp -label "Small Fish Colour” -rgb 1 1 1 -cc “eval ($changeColor)sliderB;

Note that the command you are building gets the color from something named “sliderA”.
Note that the line that builds the slider uses that string ($changeColor) for the command, but the name you are giving the slider (the last parameter on the line) is “sliderB”.
Without running the code I can see that every time you move sliderB it will extract the rgb value of sliderA and set that value to $shader, which was “Small_Fish1_M”.

I hope that will help you.

<* Wes *>



Replies: 0
avatar
  • R*
  • Posted: 30 December 2011 08:11 PM

I understand, so how would I go about fixing this? I’m still learning MEL so I’m not sure what to do.

Changing both values to sliderB causes the shark control to stop working but the small fish control works fine.

setAttr "Shark_M.color"

    
string $shader "Shark_M"// The shader to be controlled by the slider
    
string $changeColor "float $curColor[] = `colorSliderGrp -q -rgbValue sliderA`;setAttr " + ($shader) + ".color -type double3 $curColor[0] $curColor[1] $curColor[2];";
    
colorSliderGrp -label "Shark Colour" -rgb 1 1 1 -dc "eval ($changeColor)sliderA;

setAttr "Small_Fish1_M.color"

    
string $shader "Small_Fish1_M"// The shader to be controlled by the slider
    
string $changeColor "float $curColor[] = `colorSliderGrp -q -rgbValue sliderB`;setAttr " + ($shader) + ".color -type double3 $curColor[0] $curColor[1] $curColor[2];";
    
colorSliderGrp -label "Small Fish Colour" -rgb 1 1 1 -dc "eval ($changeColor)sliderB;

As for testing it, you could create 3 spheres and assign a normal Lambert shader to the first sphere and that lamber shader will be called Shark_M. The second sphere will have a lambert shader called Small_Fish1_M and the third sphere will have a lambert shader called Large_Fish_M.

I’ve tried this and i still encounter the same problems but you can use this for testing purposes.

This is confusing. I’m sure there’s a simple solution but I can’t find it! I’ve looked everywhere for help but it looks like I’m the only one who has this problem.

Thanks.



Replies: 0
avatar

The other problem I noticed this time is that you are using the same variable name $shader in both commands. It can only have one value at a time, not both.

What you are using $shader for is to build a string that will be used as a MEL command any time that the slider is changed. The command you need is different for each slider, but with only one variable name you are getting the right command for one and the wrong for the other.

Make a unique name for each, like $shaderA or something.

<* Wes *>



Replies: 0
avatar
  • R*
  • Posted: 02 January 2012 11:51 PM

YES!!!!

I’ve finally figured it out, thanks to you. It turns out, that most of the strings have to be unique:

setAttr "Shark_M.color"

    
string $shader "Shark_M"// The shader to be controlled by the slider
    
string $changeColor "float $curColor[] = `colorSliderGrp -q -rgbValue sliderA`;setAttr " + ($shader) + ".color -type double3 $curColor[0] $curColor[1] $curColor[2];";
    
colorSliderGrp -label "Shark Colour" -rgb 1 1 1 -dc "eval ($changeColor)sliderA;

setAttr "Small_Fish1_M.color"

    
string $shaderB "Small_Fish1_M"// The shader to be controlled by the slider
    
string $changeColorB "float $curColor[] = `colorSliderGrp -q -rgbValue sliderB`;setAttr " + ($shaderB) + ".color -type double3 $curColor[0] $curColor[1] $curColor[2];";
    
colorSliderGrp -label "Small Fish Colour" -rgb 1 1 1 -dc "eval ($changeColorB)sliderB;

setAttr "Large_Fish_M.color"

    
string $shaderC "Large_Fish_M"// The shader to be controlled by the slider
    
string $changeColorC "float $curColor[] = `colorSliderGrp -q -rgbValue sliderC`;setAttr " + ($shaderC) + ".color -type double3 $curColor[0] $curColor[1] $curColor[2];";
    
colorSliderGrp -label "Large Fish Colour" -rgb 1 1 1 -dc "eval ($changeColorC)sliderC;

Thanks for your help!



Replies: 1
/userdata/avatar/avatar_281222.jpg

You’re welcome.
Most of your problems are common to programming in general, rather than specific to MEL. MEL is much like C, and I go back a long way with C.
I hope you get a good grade on your project.

<* Wes *>

Author: Wesley Howe

Replied: 03 January 2012 03:19 PM  
avatar
  • R*
  • Posted: 03 January 2012 11:13 PM

Thanks Wes.



Replies: 1
/userdata/avatar/5e2c402t2.jpg

Wes’s MEL-KungFu is strong
=)

Author: n8skow

Replied: 06 January 2012 09:56 AM