color switch

51 views
Skip to first unread message

Christopher.

unread,
Oct 4, 2015, 2:15:53 PM10/4/15
to Python Programming for Autodesk Maya
I want to change the color of a sphere using Switch in MEL this is what I have thus far, it is not working ? 

Can you store RGB values in a int ?

string $obj_sphere = pSphere1;
int $color = 22, 204, 61;
switch ($color) {
   
case $obj_sphere: 104,160,60;
   
break;
   
}

Justin Israel

unread,
Oct 4, 2015, 2:51:55 PM10/4/15
to Python Programming for Autodesk Maya

Arrays:
http://download.autodesk.com/global/docs/maya2014/en_us/files/Arrays_vectors_and_matrices_Arrays.htm

Vectors:
http://download.autodesk.com/global/docs/maya2014/en_us/index.html?url=files/Arrays_vectors_and_matrices_Vectors.htm,topicNumber=d30e790326


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c7e7983f-99f3-4ba2-805e-111f9c614144%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher.

unread,
Oct 4, 2015, 3:27:27 PM10/4/15
to Python Programming for Autodesk Maya
The color values should be in an array ?
$color = [22,204,61],[34,56,165];


On Sunday, October 4, 2015 at 2:51:55 PM UTC-4, Justin Israel wrote:
On Mon, 5 Oct 2015 7:15 AM Christopher. <crestchr...@gmail.com> wrote:
I want to change the color of a sphere using Switch in MEL this is what I have thus far, it is not working ? 

Can you store RGB values in a int ?

string $obj_sphere = pSphere1;
int $color = 22, 204, 61;
switch ($color) {
   
case $obj_sphere: 104,160,60;
   
break;
   
}

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Oct 4, 2015, 4:34:44 PM10/4/15
to python_in...@googlegroups.com

The switch statement has some limitations for your application. You can’t use an array as a switch expression, and you can’t use vector variables as switch cases…

Vector with switch:

vector $myColor = <<0, 0, 1.0>>;

switch ($myColor){
    case <<1.0, 0, 0>>:
        print "RED!";
        break;
    case <<1.0, 1.0, 1.0>>:
        print "WHITE!";
        break;

    case <<0, 0, 1.0>>:
        print "'merica!";
        break;

    default:
        print "nada.";
        break;

}

Array with if-else:

int $redColor[3] = {255, 0, 0};
int $whiteColor[3] = {255, 255, 255};

int $blueColor[3] = {0, 0, 255};

$myColor2 = $blueColor;

// Because I barely know MEL these days and I don't know
// a better way to compare int arrays.
proc int equalColors(int $left[], int $right[]) {
    if (size($left) != 3) {
        return false;
    }
    if (size($right) != 3) {
        return false;
    }

    int $i;
    for ($i=0; $i < 3; $i++) {
        if ($left[$i] != $right[$i]) {
            return false;
        }
    }
    return true;
}

if (equalColors($myColor2, $redColor)) {
    print "RED!";
} else if (equalColors($myColor2, $whiteColor)) {
    print "WHITE!";
} else if (equalColors($myColor2, $blueColor)) {
    print "'merica!";
} else {
    print "nada.";
}

You are probably better off with an if-else.

Justin

On Mon, Oct 5, 2015 at 8:27 AM Christopher. crestchr...@gmail.com wrote:

The color values should be in an array ?
$color = [22,204,61],[34,56,165];


On Sunday, October 4, 2015 at 2:51:55 PM UTC-4, Justin Israel wrote:
On Mon, 5 Oct 2015 7:15 AM Christopher. <crestchr...@gmail.com> wrote:
I want to change the color of a sphere using Switch in MEL this is what I have thus far, it is not working ? 

Can you store RGB values in a int ?

string $obj_sphere = pSphere1;
int $color = 22, 204, 61;
switch ($color) {
   
case $obj_sphere: 104,160,60;
   
break;
   
}

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3a3b5ef5-467d-47c4-9548-97e600f0ecef%40googlegroups.com.

Crest Christopher

unread,
Oct 4, 2015, 5:27:06 PM10/4/15
to python_in...@googlegroups.com
How do you know what color 0,0,1.0 is ?

Justin Israel wrote:
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/Xxm27BNbA6s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA262Aq812pPSDwgWJZcWZbGmpAo3%3DqDN8D%3DtccTqE4zbQ%40mail.gmail.com.

Justin Israel

unread,
Oct 4, 2015, 6:24:09 PM10/4/15
to python_in...@googlegroups.com
https://en.wikipedia.org/wiki/RGB_color_model#Numeric_representations

Maya's color values are floating point (as far as I know)

Reply all
Reply to author
Forward
0 new messages