Home Coding, Scripting, Shaders

Mel script - Repeat current poly reduce function on all selected objects?

jt_knight
polycounter lvl 2
Offline / Send Message
jt_knight polycounter lvl 2

I'm looping through multiple objects, but the loop stops before going to the next object.

Created a loop with condition. If condition is met, it calls a ReduceEdge() function. Problem is it will only iterate once and not go to the next object and repeat the procedure.

global proc ReduceEdge()
{
    polySelectEdgesEveryN "edgeRing" 2; 
    polySelectEdgesEveryN "edgeLoop" 1;
    polyDelEdge -cv on;
}

string $newSel[] = `ls -sl`;

for($i = 0; $i < size($newSel); $i++)
{
    select $newSel[$i];
    int $polyEval[] = `polyEvaluate -e $newSel[$i]`;
    int $temp = $polyEval[0];

    for($k = 0; $k < $temp; $k++)
    {    
        string $polyInfo[] = `polyInfo -fn ($newSel[$i] + ".f[" + $k + "]")`;
        $polyInfo = stringToStringArray($polyInfo[$i]," ");

        float $vPosX = $polyInfo[2];
        float $vPosY = $polyInfo[3];
        float $vPosZ = $polyInfo[4];   

        if($vPosX == 0 && $vPosY == 0 && $vPosZ == 1.0)
        {   
            select ($newSel[$i] + ".e[" + $k + "]");              
            ReduceEdge();
        }
    }
}

Expected results: If I select 4 cylinders, all their edges will reduce by half the current amount.

Actual results: 
When 4 cylinders are selected, only one reduces down to half the edges. The rest stay the same.

Replies

Sign In or Register to comment.