Hello everyone,
Mostly for educational purposes I'm trying to create a simple rotate tool UI window. But I feel I'm stuck on the Mel syntax and various things I tried just don't work.
-I'm using a switch case statement, but I'm wondering if I can omit this by directly inserting the axis into the rotate mel command arguments. Is this possible?
-The procedure to get the state of the radio buttons is something that I found on the Internet, do I really need this procedure to get the state of the radio buttons or is there a simpler way?
-My current error is:
// Error: Line 3.51: "$axisCollection" is an undeclared variable. //
Can anyone help me to fix this script so it works?
global proc RotateSelected(){<br> <br> string $axis = `get_radio_state($axisCollection)`;<br> <br> switch ($axis){<br> case "x":<br> rotate -r -x 10 0 0;<br> break;<br> case "y":<br> rotate -r -y 10 0 0;<br> break;<br> case "z":<br> rotate -r -z 10 0 0;<br> break;<br> <br> }<br>} <br><br>global proc string get_radio_state(string $radio)<br>{<br> string $selected = `radioCollection -q -select $radio`;<br> return `radioButton -q -label $selected`;<br>}<br><br><br>if (`window -exists myWindow`) deleteUI myWindow;<br>window -title "new window" -widthHeight 300 200 myWindow;<br> scrollLayout scrollLayout;<br> columnLayout -adjustableColumn true;<br> <br> frameLayout -label "Axis";<br><br> rowLayout -nc 3;<br> string $axisCollection = `radioCollection`;<br> radioButton -label "x";<br> radioButton -label "y";<br> radioButton -label "z";<br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Degrees";<br><br> rowLayout -nc 6;<br> string $degreesCollection = `radioCollection`;<br> radioButton -label "90";<br> radioButton -label "45";<br> radioButton -label "30";<br> radioButton -label "22,5";<br> radioButton -label "10";<br> radioButton -label "5"; <br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Rotate" -lv false;<br><br> rowLayout -nc 2;<br> button -label "-" -w 32 -h 32 -c ("RotateSelected") ;<br> button -label "+" -w 32 -h 32 -c "RotateSelected";<br> setParent ..;<br> setParent ..;<br><br><br>showWindow;
Replies
global proc RotateSelected(){<br> <br> rotate -r ("-"+(`get_radio_state("axisCollection")`)) `get_radio_state("degreesCollection")`;<br> } <br><br>global proc string get_radio_state(string $radio)<br> {<br> string $selected = `radioCollection -q -select $radio`;<br> return `radioButton -q -label $selected`;<br> }<br><br><br> if (`window -exists myWindow`) deleteUI myWindow;<br> window -title "new window" -widthHeight 300 200 myWindow;<br> scrollLayout scrollLayout;<br> columnLayout -adjustableColumn true;<br> <br> frameLayout -label "Axis";<br><br> rowLayout -nc 3;<br> radioCollection "axisCollection";<br> radioButton -label "x" -sl;<br> radioButton -label "y";<br> radioButton -label "z";<br> <br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Degrees";<br><br> rowLayout -nc 6;<br> radioCollection "degreesCollection";<br> radioButton -label "90" -sl;<br> radioButton -label "45";<br> radioButton -label "30";<br> radioButton -label "22,5";<br> radioButton -label "10";<br> radioButton -label "5"; <br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Rotate" -lv false;<br><br> rowLayout -nc 2;<br> button -label "-" -w 32 -h 32 -c ("RotateSelected") ;<br> button -label "+" -w 32 -h 32 -c "RotateSelected";<br> setParent ..;<br> setParent ..;<br> <br> <br> <br><br> showWindow;You can name your layouts instead of doing a new variable.global proc RotateSelected(string $way){<br> <br> rotate -r ("-"+(`get_radio_state("axisCollection")`)) (($way)+`get_radio_state("degreesCollection")`);<br> } <br><br>global proc string get_radio_state(string $radio)<br> {<br> string $selected = `radioCollection -q -select $radio`;<br> return `radioButton -q -label $selected`;<br> }<br><br><br> if (`window -exists myWindow`) deleteUI myWindow;<br> window -title "new window" -widthHeight 300 200 myWindow;<br> scrollLayout scrollLayout;<br> columnLayout -adjustableColumn true;<br> <br> frameLayout -label "Axis";<br><br> rowLayout -nc 3;<br> radioCollection "axisCollection";<br> radioButton -label "x" -sl;<br> radioButton -label "y";<br> radioButton -label "z";<br> <br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Degrees";<br><br> rowLayout -nc 6;<br> radioCollection "degreesCollection";<br> radioButton -label "90" -sl;<br> radioButton -label "45";<br> radioButton -label "30";<br> radioButton -label "22.5";<br> radioButton -label "10";<br> radioButton -label "5"; <br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Rotate" -lv false;<br><br> rowLayout -nc 2;<br> button -label "-" -w 32 -h 32 -c "RotateSelected(\"-\")";<br> button -label "+" -w 32 -h 32 -c "RotateSelected(\"\")";<br> setParent ..;<br> setParent ..;<br> <br> <br> <br><br> showWindow;I'm trying to extend the script further, with adjustable pivot points. However, with the script below i get the following error when choosing the 'origin' option and i don't understand why:
// Error: line 9: Invalid flag '-pivot 0 0 0' //
The other pivot options are working correctly.
global proc RotateSelected(string $way){<br> <br> $pivot = `get_radio_state("pivotCollection")`; <br> string $pivotFlag = "";<br> if ($pivot == "local") $pivotFlag = "-ocp";<br> else if ($pivot == "group") $pivotFlag = "-cp";<br> else if ($pivot == "origin") $pivotFlag = "-pivot 0 0 0";<br> <br> rotate -r $pivotFlag ("-"+(`get_radio_state("axisCollection")`)) (($way)+`get_radio_state("degreesCollection")`) ;<br> } <br><br> global proc string get_radio_state(string $radio)<br> {<br> string $selected = `radioCollection -q -select $radio`;<br> return `radioButton -q -label $selected`;<br> }<br><br><br> if (`window -exists myWindow`) deleteUI myWindow;<br> window -title "new window" -widthHeight 300 200 myWindow;<br> scrollLayout scrollLayout;<br> columnLayout -adjustableColumn true;<br> <br> frameLayout -label "Axis";<br><br> rowLayout -nc 3;<br> radioCollection "axisCollection";<br> radioButton -label "x" -sl;<br> radioButton -label "y";<br> radioButton -label "z";<br> <br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Degrees";<br><br> rowColumnLayout -nc 3;<br> radioCollection "degreesCollection";<br> radioButton -label "180";<br> radioButton -label "120";<br> radioButton -label "90" -sl;<br> radioButton -label "45";<br> radioButton -label "30";<br> radioButton -label "22.5";<br> radioButton -label "10";<br> radioButton -label "5";<br> radioButton -label "1"; <br> setParent ..;<br> setParent ..;<br> <br> frameLayout -label "pivot";<br><br> rowLayout -nc 3;<br> radioCollection "pivotCollection";<br> radioButton -label "local" -sl;<br> radioButton -label "group";<br> radioButton -label "origin";<br> <br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Rotate" -lv false;<br><br> rowLayout -nc 3;<br> button -label "-" -w 32 -h 32 -c "RotateSelected(\"-\")";<br> button -label "+" -w 32 -h 32 -c "RotateSelected(\"\")";<br> button -label "Reset" -w 32 -h 32 -c "rotate -a 0 0 0";<br> setParent ..;<br> setParent ..;<br> <br> <br> <br><br> showWindow;<br>It's a bit tricky cause you will need those floats only in origin mode.
Maybe you will have to make specific rotate commands for each case.
<br>global proc RotateSelected(string $way){<br> <br> $pivot = `get_radio_state("pivotCollection")`; <br> $axis = ("-"+(`get_radio_state("axisCollection")`));<br> $degrees = (($way)+`get_radio_state("degreesCollection")`);<br><br> if ($pivot == "local")<br> rotate -r -ocp $axis $degrees;<br> else if ($pivot == "group")<br> rotate -r -cp $axis $degrees;<br> else if ($pivot == "origin")<br> rotate -r -p 0 0 0 $axis $degrees;<br>} <br><br> global proc string get_radio_state(string $radio)<br> {<br> string $selected = `radioCollection -q -select $radio`;<br> return `radioButton -q -label $selected`;<br> }<br><br><br> if (`window -exists myWindow`) deleteUI myWindow;<br> if (`windowPref -exists myWindow`) windowPref -remove myWindow;<br> window -title "new window" -widthHeight 170 206 myWindow;<br> scrollLayout scrollLayout;<br> columnLayout -adjustableColumn true;<br> <br> frameLayout -label "Axis";<br><br> rowLayout -nc 3;<br> radioCollection "axisCollection";<br> radioButton -label "x" -sl;<br> radioButton -label "y";<br> radioButton -label "z";<br> <br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Degrees";<br><br> rowColumnLayout -nc 3;<br> radioCollection "degreesCollection";<br> radioButton -label "180";<br> radioButton -label "120";<br> radioButton -label "90" -sl;<br> radioButton -label "45";<br> radioButton -label "30";<br> radioButton -label "22.5";<br> radioButton -label "10";<br> radioButton -label "5";<br> radioButton -label "1"; <br> setParent ..;<br> setParent ..;<br> <br> frameLayout -label "pivot";<br><br> rowLayout -nc 3 ;<br> radioCollection "pivotCollection";<br> radioButton -label "local" -sl;<br> radioButton -label "group";<br> radioButton -label "origin";<br> <br> setParent ..;<br> setParent ..;<br> <br> <br> frameLayout -label "Rotate" -lv false;<br><br> rowLayout -nc 3 -cl3 "left" "center" "right";<br> button -label "-" -w 32 -h 32 -c "RotateSelected(\"-\")";<br> button -label "+" -w 32 -h 32 -c "RotateSelected(\"\")";<br> button -label "Reset" -w 32 -h 32 -c "rotate -a 0 0 0";<br> setParent ..;<br> setParent ..;<br> <br> <br> <br><br> showWindow;<br>