CrustedInk
07-20-2008, 06:47 PM
Hey.
I just wrote my first "real" mel-script. Nothing big, it resets all selected Objects.
actually, it works. but i wanted an ui, with 3 checkboxes. 1 for every attribute (translate, rotate, scale). the idea was, that you can click on the button in the shelf, and the script resets everything. the ui pops up when you click with pressed ctrlon it. That works with some help of a friend. the next time you click on the button, the script should run with the last settings.
the probleme.. there some undeclared variable, but i don't know how to fix it.Maybe somebody could help me with this. my idea was, that you have to run the script for the first time with the ctrl+click, thats why i declared the variables in the if_clause.
if (keysPressed() == "Ctrl")
{
$cb_s2 = 0;
$cb_t2 = 0;
$cb_r2 = 0;
window -wh 200 256;
columnLayout;
checkBox -label "Translate" -value $cb_t2 -onc "$cb_t2 = 1" -ofc "$cb_t2 = 0";
checkBox -label "Rotate" -value $cb_r2 -onc "$cb_r2 = 1" -ofc "$cb_r2 = 0";
checkBox -label "Scale" -value $cb_s2 -onc "$cb_s2 = 1" -ofc "$cb_s2 = 0";
button -label "Reset 'em " -command "dr_resetObj_proc(`ls -sl`,$cb_t2,$cb_s2,$cb_r2)";
showWindow;
}
else
dr_resetObj_proc(`ls -sl`,$cb_t2,$cb_r2,$cb_s2);
global proc string keysPressed()
{
int $mods = `getModifiers`;
string $keys = "";
if (($mods / 1) % 2)
{
if ($keys == "") $keys += ("Shift");
else $keys += (" Shift");
}
if (($mods / 2) % 2)
{
if ($keys == "") $keys += ("CapsLock");
else $keys += (" CapsLock");
}
if (($mods / 4) % 2)
{
if ($keys == "") $keys += ("Ctrl");
else $keys += (" Ctrl");
}
if (($mods / 8) % 2)
{
if ($keys == "") $keys += ("Alt");
else $keys += (" Alt");
}
return $keys;
};
global proc dr_resetObj_proc(string $ctrl_reset[], string $cb_t2, string $cb_s2,string $cb_r2)
{
for($i=0;$i<`size $ctrl_reset`;$i++)
{
if ($cb_t2 == 1)
{
setAttr ($ctrl_reset[$i] + ".translateX") 0;
setAttr ($ctrl_reset[$i] + ".translateY") 0;
setAttr ($ctrl_reset[$i] + ".translateZ") 0;
}
if ($cb_s2 == 1)
{
setAttr ($ctrl_reset[$i] + ".scaleX") 1;
setAttr ($ctrl_reset[$i] + ".scaleY") 1;
setAttr ($ctrl_reset[$i] + ".scaleZ") 1;
}
if ($cb_r2 == 1)
{
setAttr ($ctrl_reset[$i] + ".rotateX") 0;
setAttr ($ctrl_reset[$i] + ".rotateY") 0;
setAttr ($ctrl_reset[$i] + ".rotateZ") 0;
}
}
};
I just wrote my first "real" mel-script. Nothing big, it resets all selected Objects.
actually, it works. but i wanted an ui, with 3 checkboxes. 1 for every attribute (translate, rotate, scale). the idea was, that you can click on the button in the shelf, and the script resets everything. the ui pops up when you click with pressed ctrlon it. That works with some help of a friend. the next time you click on the button, the script should run with the last settings.
the probleme.. there some undeclared variable, but i don't know how to fix it.Maybe somebody could help me with this. my idea was, that you have to run the script for the first time with the ctrl+click, thats why i declared the variables in the if_clause.
if (keysPressed() == "Ctrl")
{
$cb_s2 = 0;
$cb_t2 = 0;
$cb_r2 = 0;
window -wh 200 256;
columnLayout;
checkBox -label "Translate" -value $cb_t2 -onc "$cb_t2 = 1" -ofc "$cb_t2 = 0";
checkBox -label "Rotate" -value $cb_r2 -onc "$cb_r2 = 1" -ofc "$cb_r2 = 0";
checkBox -label "Scale" -value $cb_s2 -onc "$cb_s2 = 1" -ofc "$cb_s2 = 0";
button -label "Reset 'em " -command "dr_resetObj_proc(`ls -sl`,$cb_t2,$cb_s2,$cb_r2)";
showWindow;
}
else
dr_resetObj_proc(`ls -sl`,$cb_t2,$cb_r2,$cb_s2);
global proc string keysPressed()
{
int $mods = `getModifiers`;
string $keys = "";
if (($mods / 1) % 2)
{
if ($keys == "") $keys += ("Shift");
else $keys += (" Shift");
}
if (($mods / 2) % 2)
{
if ($keys == "") $keys += ("CapsLock");
else $keys += (" CapsLock");
}
if (($mods / 4) % 2)
{
if ($keys == "") $keys += ("Ctrl");
else $keys += (" Ctrl");
}
if (($mods / 8) % 2)
{
if ($keys == "") $keys += ("Alt");
else $keys += (" Alt");
}
return $keys;
};
global proc dr_resetObj_proc(string $ctrl_reset[], string $cb_t2, string $cb_s2,string $cb_r2)
{
for($i=0;$i<`size $ctrl_reset`;$i++)
{
if ($cb_t2 == 1)
{
setAttr ($ctrl_reset[$i] + ".translateX") 0;
setAttr ($ctrl_reset[$i] + ".translateY") 0;
setAttr ($ctrl_reset[$i] + ".translateZ") 0;
}
if ($cb_s2 == 1)
{
setAttr ($ctrl_reset[$i] + ".scaleX") 1;
setAttr ($ctrl_reset[$i] + ".scaleY") 1;
setAttr ($ctrl_reset[$i] + ".scaleZ") 1;
}
if ($cb_r2 == 1)
{
setAttr ($ctrl_reset[$i] + ".rotateX") 0;
setAttr ($ctrl_reset[$i] + ".rotateY") 0;
setAttr ($ctrl_reset[$i] + ".rotateZ") 0;
}
}
};
