hey guys, can you tell me what i am doing wrong? I did a mel script to select the objects by having its name and number. It randomly selects half of it each time i click the button. I run it once, modify the objects, but when i roll it again maya freezes. what
As such nothing wrong in ur script. Put few print commands inside n outside the while loop and check at what place maya freezes..., if it continue to print for long time ur running a endless loop. otherwise it'll freeze after a particular print command to give a clue..
hi
as raaajjj (<-- nice name btw .. ^^) said - there's nothing wrong in your script. i can push the button as much as i want to and my computer doesn't freeze. also the code looks accurate. may you take the script and test it on another computer.
but one thing at the script and your description. you wanted the script to select half of the objects which you decided with the name and number. if you want the script to do this just take this one.
CODE
global proc TEST()
{
// Ramdom Selector
if (window -ex sel == 1)
deleteUI sel;
window -t "Random Select" -widthHeight 300 150 sel;
columnLayout;
textField -tx "pCube" -w 150 randomButton;
textField -tx "18" -w 150 numberButton;
button -l "Random Select" -c random_select randomclick;
showWindow sel;
}
global proc random_select()
{
string $prefix = textField -q -tx randomButton;
int $number = textField -q -tx numberButton;
string $obj;
int $r;
int $i = 0;
select -cl;
while ($i < ($number/2))
{
$i++;
$r = rand(1,$number);
$r = trunc($r);
$obj = $prefix + $r;
select -add $obj;
string $currentSelection[] = ls -sl;
int $selSize = size($currentSelection);
if ($i > $selSize)
{
$i = $selSize;
}
}
}