Home Coding, Scripting, Shaders

(MEL) unable to group uvs based on Area(Size)

polycounter lvl 16
Offline / Send Message
onionhead_o polycounter lvl 16
trying to write a procedure thats groups the uvs shells into 3 seperate categories (Small, Medium, Large). but running into an issue where small uv shells doesnt get cast to the correct array $uvShellSmlList. Im been spending the whole day looking and testing to see why its doing that.

Note this code only works on maya 2017.4 +  since texGetShell is a new procedure after uvToolkit was added.

global proc float[] getUVShellArea(){<br>	global string $shellList[];<br>	$shellList =`texGetShells`;<br>	float $shellArea[];<br>	//print $shellList;<br>	//print (size($shellList));<br>    for ($i = 0; $i < `size($shellList)`; $i++)<br>    {<br>        <br>        string $tempList[] = stringToStringArray($shellList[$i], " ");<br><br>        // Calculate shell UV area<br>        string $faceList[] = `polyListComponentConversion -fromUV -toFace $tempList`;<br>        $faceAreas = `polyEvaluate -uvFaceArea $faceList`; // polyEvaluate returns a float[]<br>        float $totalArea;<br>        for ($faceArea in $faceAreas)<br>            $totalArea += $faceArea;<br>         $shellArea[$i] = $totalArea;<br>	}<br>	//print $shellArea;<br>	return $shellArea;<br>}<br><br>// sum of total Area of all shells then divided by TotalShells to get Average area. function to group shells according the area. Split into 3 categories (Small,Mid,Large)<br>global proc string[] uvShellCompare(){<br>	global string $shellList[];<br>	float $shellArea[] = `getUVShellArea`;<br>	float $sortedShellAreaList[] = `sort $shellArea`;<br>	float $shellAreaMin = $sortedShellAreaList[0]; //gets the smallest shell <br>	float $shellAreaMax = $sortedShellAreaList[size($shellArea)]; //gets the largest shell<br>	float $shellAreaAvg;<br>	float $shellAreaTotalSum;<br>	string $uvShellSmlList[];<br>	string $uvShellMidList[];<br>	string $uvShellLarList[];<br>	string $combShellList[];<br>	for ($tmpshellAreas in  $shellArea)<br>         $shellAreaTotalSum += $tmpshellAreas;<br>         <br>    print $shellAreaTotalSum;<br>         <br>    //$shellAreaAvg = $shellAreaTotalSum / (size($shellArea)); // may not use this method in cases where theres a large disparity between shell sizes<br>    //(len - 1) / 2 and len / 2    even/odd<br>    if ((size ($sortedShellAreaList)) % 2 == 0){ <br>   		 //even<br>    	$shellAreaAvg = $sortedShellAreaList[((size ($sortedShellAreaList)) - 1)/ 2];<br>    }<br>        //odd<br>    if ((size ($sortedShellAreaList)) % 2 != 0){<br>    	$shellAreaAvg = $sortedShellAreaList[(size ($sortedShellAreaList))/ 2];<br>    	}<br>    <br>    print ("\n" + $shellAreaAvg);<br>    <br>	for ($i = 0; $i <= `size($shellArea)`; $i++)<br>	{<br>		if ($shellArea[$i] < $shellAreaAvg && (equivalentTol($shellArea[$i],$shellAreaAvg,0.03) == 0))<br>		{<br>			$uvShellSmlList[size($uvShellSmlList)] = $shellList[$i];<br>			}<br>			<br>		if ($shellArea[$i] == $shellAreaAvg || (equivalentTol($shellArea[$i],$shellAreaAvg,0.03) == 1))<br>		{<br>			$uvShellMidList[size($uvShellMidList)] = $shellList[$i];<br>			}<br>			<br>		if ($shellArea[$i] > $shellAreaAvg && (equivalentTol($shellArea[$i],$shellAreaAvg,0.01) == 0))<br>		{<br>			$uvShellLarList[size($uvShellLarList)] = $shellList[$i];<br>			}<br>	}<br>	$combShellList[0] = stringArrayToString($uvShellSmlList, " ");<br>	$combShellList[1] = stringArrayToString($uvShellMidList, " ");<br>	$combShellList[2] = stringArrayToString($uvShellLarList, " ");<br>	return $combShellList;<br><br>}<br><br>{<br>	string $testList[] = `uvShellCompare`;<br>	print "\n";<br>	print "Small ";<br>	print $testList[0];<br>	print "\n";<br>	print "Medium ";<br>	print $testList[1];<br>	print "\n";<br>	print "Large ";<br>	print $testList[2];<br>	}



Replies

  • ProperSquid
    Options
    Offline / Send Message
    ProperSquid polycounter lvl 12
    Just throwing a random guess out there, but my guess is when you sort shellArea, you are losing the indexes of the mesh, and that's why it isn't working as expected. If I were to do this in Python, I'd instead do something like this:

    # Assuming that getUVShellArea is a Python function.
    shellArea = getUVShellArea()

    # Enumerate will return a tuple of the index and the value in the shellArea
    # list. For example, if we have a list of two items, it'd look something like
    # this:
    # [(0, 5.0), (1, 4.3)]
    sortedShellAreaList = list(enumerate(shellArea))
    # Sort the list by the second item in the tuple.
    # Now the list will look something like this:
    # [(1, 4.3), (0, 5.0)]
    sortedShellAreaList.sort(key=lambda x: x[1])

    # Continue on from there

  • onionhead_o
    Options
    Offline / Send Message
    onionhead_o polycounter lvl 16
    thanks for the tip. I will double check on the sorted list part.

    Yeh i wish mel has tuples. not sure why they dont have it. So from what I understand is you put both the shells and the area together into the tuple and sorted it?

    If you dont mind i have another question. How do you separate numbers and group them. for example   rawNumbers = (0.2, 0.3 , 0.12, 2 ,3 ,7 ,10)  >>>>>>>> SmlNum = (0.12, 0.2, 0.3) MidNum = (2,3) LarNum(7,10). in my code im trying to use equivalentTol, which in my case is suppose to compare the numbers with a tolerance. I find it hard to troubleshoot.


  • ProperSquid
    Options
    Offline / Send Message
    ProperSquid polycounter lvl 12
    You're right about the first bit. Also, here's a way you can do the second part:

    mid = 0.0
    low = 0.0
    areas = set()

    # Get all of the areas, and make sure they're unique.
    for _, area in sortedShellArea:
        areas.add(area)

    # Convert the areas into a sorted list.
    areas = sorted(areas)
    # Pick an area that is in about the 2/3rds index position in the list, or
    # roughly mid.
    mid = max(mid, areas[int(len(areas) * 2.0 / 3.0]))
    # Pick an area that is in about the 1/3rds index position in the list, or
    # roughly low.
    low = max(low, areas[int(len(areas) * 1.0 / 3.0]))

    highAreas = []
    midAreas = []
    lowAreas = []

    # Go through the sorted shell list. If the area is less than or equal to low,
    # then it is low. If it is less than or equal to mid, then it is mid, otherwise
    # it is high.
    for index, area in sortedShellArea:
         if area <= low:
            lowAreas.append((index, area))
         elif area <= mid:
            midAreas.append((index, area))
         else:
            highAreas.append((index, area))

  • onionhead_o
    Options
    Offline / Send Message
    onionhead_o polycounter lvl 16
    ahh I see im gona try translating this in mel. I know i know python is better. but i dont have time to recode everything. This is part of a large procedure which has 800+ lines. Thanks for your help. I will post the solution up once i have something working.
  • onionhead_o
    Options
    Offline / Send Message
    onionhead_o polycounter lvl 16
    i tried to get as far as i can. but stuck on some syntax.
    <div>//derived from texSortShellsByBounds, uses same idea of combining the shellarea into the shelllist<br><br>global proc string[] sortShellsByUVArea(string $shellList[]){<br>&nbsp;&nbsp;&nbsp; global string $shellArea[];<br>&nbsp;&nbsp;&nbsp; string $prefixList[];<br><br>&nbsp;&nbsp;&nbsp; for ($i = 0; $i < `size($shellList)`; $i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $temp[] = stringToStringArray($shellList[$i], " ");<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $faceList[] = `polyListComponentConversion -fromUV -toFace $temp`;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $faceAreas = `polyEvaluate -uvFaceArea $faceList`; // polyEvaluate returns a float[]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float $area;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($faceArea in $faceAreas)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $area += $faceArea;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $shellArea[$i] = $area;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $prefixList[$i] = ($shellArea[$i] + "%" + $shellList[$i]);<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>string $sortedShellList[];<br><br>$sortedShellList = `sort($prefixList)`;<br><br>&nbsp;&nbsp;&nbsp; return $sortedShellList;<br>}<br><br>global proc string[] uvShellCompare(){<br><br>&nbsp;&nbsp;&nbsp; float $lowNum;<br>&nbsp;&nbsp;&nbsp; float $midNum;<br>&nbsp;&nbsp;&nbsp; string $rawShellList[] = `texGetShells` ;<br>&nbsp;&nbsp;&nbsp; string $shellSmlList[];<br>&nbsp;&nbsp;&nbsp; string $shellMidList[];<br>&nbsp;&nbsp;&nbsp; string $shellLarList[];<br>&nbsp;&nbsp;&nbsp; //float $highNum; no need anymore<br>&nbsp;&nbsp;&nbsp; float $finalShellArea[];<br>&nbsp;&nbsp;&nbsp; string $finalShellList[];<br>&nbsp;&nbsp;&nbsp; string $combShellList[];<br>&nbsp;&nbsp;&nbsp; string $sortedShellList[] = sortShellsByUVArea($rawShellList); //call procedure<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; for ($i = 0; $i < size($sortedShellList); $i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $regex = "[^ ]+ *";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $buffer[];<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $finalShellList[$i] = `substitute $regex $sortedShellList[$i] ""`;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tokenize($sortedShellList[$i], "%", $buffer);<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $finalShellArea[$i] =&nbsp; `float($buffer[0])`;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; $lowNum = $finalShellArea[(int(size($finalShellArea)* 1.0 / 3.0)];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $midNum = $finalShellArea[(int(size($finalShellArea)* 2.0 / 3.0)];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for ($i = 0; $i < size($finalShellArea); $i++)<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ($finalShellArea <= lowNum){<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $shellSmlList[size($shellSmlList)] = $finalShellList[$i];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ($finalShellArea <= midNum){<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $shellMidList[size($shellMidList)] = $finalShellList[$i];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $shellLarList[size($shellLarList)] = $finalShellList[$i];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $combShellList[0] = stringArrayToString($shellSmlList, " ");<br>&nbsp;&nbsp;&nbsp; $combShellList[1] = stringArrayToString($shellMidList, " ");<br>&nbsp;&nbsp;&nbsp; $combShellList[2] = stringArrayToString($shellLarList, " ");<br>&nbsp;&nbsp; return $combShellList;<br>}<br><br>uvShellCompare;<br><br></div><div><br></div>
    having syntax error on this line
     $finalShellArea[$i] =&nbsp; `float($buffer[0])`;
    Then of course the rest below fails.
  • onionhead_o
    Options
    Offline / Send Message
    onionhead_o polycounter lvl 16
    ok so after some more troubleshooting, i was able to solve the syntax errors. But getting incorrect results. where both Small shells and Medium shells identical.

    mesh to test

    new code
    <div>//derived from texSortShellsByBounds, uses same idea of combining the shellarea into the shelllist<br><br>global proc string[] sortShellsByUVArea(string $shellList[]){<br>&nbsp;&nbsp;&nbsp; global string $shellArea[];<br>&nbsp;&nbsp;&nbsp; string $prefixList[];<br><br>&nbsp;&nbsp;&nbsp; for ($i = 0; $i < `size($shellList)`; $i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $temp[] = stringToStringArray($shellList[$i], " ");<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $faceList[] = `polyListComponentConversion -fromUV -toFace $temp`;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $faceAreas = `polyEvaluate -uvFaceArea $faceList`; // polyEvaluate returns a float[]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float $area;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($faceArea in $faceAreas)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $area += $faceArea;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $shellArea[$i] = $area;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $prefixList[$i] = ($shellArea[$i] + "%" + $shellList[$i]);<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>string $sortedShellList[];<br><br>$sortedShellList = `sort($prefixList)`;<br><br>&nbsp;&nbsp;&nbsp; return $sortedShellList;<br>}<br><br>global proc string[] uvShellCompare(){<br><br>&nbsp;&nbsp;&nbsp; float $lowNum;<br>&nbsp;&nbsp;&nbsp; float $midNum;<br>&nbsp;&nbsp;&nbsp; string $rawShellList[] = `texGetShells` ;<br>&nbsp;&nbsp;&nbsp; string $shellSmlList[];<br>&nbsp;&nbsp;&nbsp; string $shellMidList[];<br>&nbsp;&nbsp;&nbsp; string $shellLarList[];<br>&nbsp;&nbsp;&nbsp; //float $highNum; no need anymore<br>&nbsp;&nbsp;&nbsp; float $finalShellArea[];<br>&nbsp;&nbsp;&nbsp; string $finalShellList[];<br>&nbsp;&nbsp;&nbsp; string $combShellList[];<br>&nbsp;&nbsp;&nbsp; string $sortedShellList[] = sortShellsByUVArea($rawShellList); //call procedure<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; for ($i = 0; $i < size($sortedShellList); $i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $regex = "[^ ]+ *";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $buffer[];<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $finalShellList[$i] = `substitute $regex $sortedShellList[$i] ""`;//removes the area prefix, leaves just the shell list<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tokenize($sortedShellList[$i], "%", $buffer);// gets the area before the %<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $finalShellArea[$i] =&nbsp; (float($buffer[0]));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; int $ArrayTokenLow = (ceil((size($finalShellArea))* (1/3)));<br>&nbsp;&nbsp;&nbsp; int $ArrayTokenMid = (ceil((size($finalShellArea))* (2/3)));<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; $lowNum = $finalShellArea[$ArrayTokenLow];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $midNum = $finalShellArea[$ArrayTokenMid];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for ($i = 0; $i < size($finalShellArea); $i++)<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ($finalShellArea[$i] <= $lowNum){<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $shellSmlList[size($shellSmlList)] = $finalShellList[$i];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ($finalShellArea[$i] <= $midNum){<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $shellMidList[size($shellMidList)] = $finalShellList[$i];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $shellLarList[size($shellLarList)] = $finalShellList[$i];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $combShellList[0] = stringArrayToString($shellSmlList, " ");<br>&nbsp;&nbsp;&nbsp; $combShellList[1] = stringArrayToString($shellMidList, " ");<br>&nbsp;&nbsp;&nbsp; $combShellList[2] = stringArrayToString($shellLarList, " ");<br>&nbsp;&nbsp; return $combShellList;<br>}<br><br>{<br>&nbsp;&nbsp;&nbsp; string $testList[] = `uvShellCompare`;<br>&nbsp;&nbsp;&nbsp; print "\n";<br>&nbsp;&nbsp;&nbsp; print "Small ";<br>&nbsp;&nbsp;&nbsp; print $testList[0];<br>&nbsp;&nbsp;&nbsp; print "\n";<br>&nbsp;&nbsp;&nbsp; print "Medium ";<br>&nbsp;&nbsp;&nbsp; print $testList[1];<br>&nbsp;&nbsp;&nbsp; print "\n";<br>&nbsp;&nbsp;&nbsp; print "Large ";<br>&nbsp;&nbsp;&nbsp; print $testList[2];<br>&nbsp;&nbsp;&nbsp; }<br><br></div>
    last bit is used to print the list

    EDIT: added some more comments
  • ProperSquid
    Options
    Offline / Send Message
    ProperSquid polycounter lvl 12
    Yeah, I think I've reached the end of my usefulness here. I tend to avoid MEL like the plague, and I don't have a copy of Maya at home, so I wouldn't be able to tinker with this. The only thing that I can offer is you should be using something like an else if or elif (not sure what the syntax is in MEL) to make sure that the mid list does not contain the low list. Otherwise the two if statements are treated as independent, when they are dependent.
  • onionhead_o
    Options
    Offline / Send Message
    onionhead_o polycounter lvl 16
    np you help me out alot already. really appreciate it. I will eventually make my way to python haha.
  • onionhead_o
    Options
    Offline / Send Message
    onionhead_o polycounter lvl 16
    i think i finally have it working decently. im currently making a tester script to select those uvs in each catergory small, medium and large. but running into syntax problem

    <div>//derived from texSortShellsByBounds, uses same idea of combining the shellarea into the shelllist<br><br>global proc string[] sortShellsByUVArea(string $shellList[]){<br>&nbsp;&nbsp;&nbsp; global string $shellArea[];<br>&nbsp;&nbsp;&nbsp; string $prefixList[];<br><br>&nbsp;&nbsp;&nbsp; for ($i = 0; $i < `size($shellList)`; $i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $temp[] = stringToStringArray($shellList[$i], " ");<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $faceList[] = `polyListComponentConversion -fromUV -toFace $temp`;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $faceAreas = `polyEvaluate -uvFaceArea $faceList`; // polyEvaluate returns a float[]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float $area;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($faceArea in $faceAreas)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $area += $faceArea;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $shellArea[$i] = $area;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $prefixList[$i] = ($shellArea[$i] + "%" + $shellList[$i]);<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>string $sortedShellList[];<br><br>$sortedShellList = `sort($prefixList)`;<br><br>&nbsp;&nbsp;&nbsp; return $sortedShellList;<br>}<br><br>global proc string[] uvShellCompare(){<br><br>&nbsp;&nbsp;&nbsp; float $lowNum;<br>&nbsp;&nbsp;&nbsp; float $midNum;<br>&nbsp;&nbsp;&nbsp; string $rawShellList[] = `texGetShells` ;<br>&nbsp;&nbsp;&nbsp; string $shellSmlList[];<br>&nbsp;&nbsp;&nbsp; string $shellMidList[];<br>&nbsp;&nbsp;&nbsp; string $shellLarList[];<br>&nbsp;&nbsp;&nbsp; //float $highNum; no need anymore<br>&nbsp;&nbsp;&nbsp; float $finalShellArea[];<br>&nbsp;&nbsp;&nbsp; string $finalShellList[];<br>&nbsp;&nbsp;&nbsp; string $combShellList[];<br>&nbsp;&nbsp;&nbsp; string $sortedShellList[] = sortShellsByUVArea($rawShellList); //call procedure<br>&nbsp;&nbsp;&nbsp; float $shellAreaTotalSum;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; for ($i = 0; $i < size($sortedShellList); $i++)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $regex = "[^ ]+ *";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string $buffer[];<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $finalShellList[$i] = `substitute $regex $sortedShellList[$i] ""`;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tokenize($sortedShellList[$i], "%", $buffer);<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $finalShellArea[$i] =&nbsp; (float($buffer[0]));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; print $finalShellArea;&nbsp;&nbsp;&nbsp; // for troubleshooting<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; $lowNum = $finalShellArea[0];<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; //finding the median value for uvshell area<br>&nbsp;&nbsp;&nbsp; if ((size ($finalShellArea)) % 2 == 0){ <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//even<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $midNum = $finalShellArea[int((size($finalShellArea) + 1) / 2)];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //odd<br>&nbsp;&nbsp;&nbsp; if ((size ($finalShellArea)) % 2 != 0){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $midNum = $finalShellArea[(size ($finalShellArea))/ 2];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print ("median is " + $midNum);<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for ($i = 0; $i < size($finalShellArea); $i++) //testing uvs for grouping, equivalentTol is like a thresold for comparing values<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ($finalShellArea[$i] <= $lowNum || equivalentTol($finalShellArea[$i], $lowNum,0.005) == 1){<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $shellSmlList[size($shellSmlList)] = $finalShellList[$i];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else if ($finalShellArea[$i] <= $midNum || equivalentTol($finalShellArea[$i], $midNum,0.03) == 1){<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $shellMidList[size($shellMidList)] = $finalShellList[$i];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else{<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $shellLarList[size($shellLarList)] = $finalShellList[$i];<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; &nbsp;$combShellList[0] = stringArrayToString($shellSmlList, " "); //Small List<br>&nbsp;&nbsp;&nbsp; $combShellList[1] = stringArrayToString($shellMidList, " "); //Medium List<br>&nbsp;&nbsp;&nbsp; $combShellList[2] = stringArrayToString($shellLarList, " "); //Large list<br>&nbsp;&nbsp; return $combShellList; //return statement for passing the list to other procedures.<br>}</div><div><br></div><div>    /**********Tester Script Portion Below********/<br>{<br>&nbsp;&nbsp;&nbsp; string $testList[] = `uvShellCompare`;<br>&nbsp;&nbsp;&nbsp; print "\n";<br>&nbsp;&nbsp;&nbsp; print "Small ";<br>&nbsp;&nbsp;&nbsp; print $testList[0];<br>&nbsp;&nbsp;&nbsp; print "\n";<br>&nbsp;&nbsp;&nbsp; print "Medium ";<br>&nbsp;&nbsp;&nbsp; print $testList[1];<br>&nbsp;&nbsp;&nbsp; print "\n";<br>&nbsp;&nbsp;&nbsp; print "Large ";<br>&nbsp;&nbsp;&nbsp; print $testList[2];<br>&nbsp;&nbsp;&nbsp; if (`window -ex SelectUVTest`) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deleteUI SelectUVTest;<br>&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; window -title "SelectUVTest" -widthHeight 100 300 -rtf true SelectUVTest;<br>&nbsp;&nbsp;&nbsp; rowColumnLayout -numberOfRows 3;<br>&nbsp;&nbsp;&nbsp; button -label "Select Small uvs" -command "select -r $testList[0]";<br>&nbsp;&nbsp;&nbsp; button -label "Select Medium uvs" -command "select -r $testList[1]";<br>&nbsp;&nbsp;&nbsp; button -label "Select Large uvs"-command "select -r $testList[2]";<br>&nbsp;&nbsp;&nbsp; showWindow;<br>&nbsp;&nbsp;&nbsp; <br>}<br><br></div>

    somehow error says $testList hasn't been declared. If you run it without this portion it will work and print the list accordingly.
    if (`window -ex SelectUVTest`) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deleteUI SelectUVTest;<br>&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; window -title "SelectUVTest" -widthHeight 100 300 -rtf true SelectUVTest;<br>&nbsp;&nbsp;&nbsp; rowColumnLayout -numberOfRows 3;<br>&nbsp;&nbsp;&nbsp; button -label "Select Small uvs" -command "select -r $testList[0]";<br>&nbsp;&nbsp;&nbsp; button -label "Select Medium uvs" -command "select -r $testList[1]";<br>&nbsp;&nbsp;&nbsp; button -label "Select Large uvs"-command "select -r $testList[2]";<br>&nbsp;&nbsp;&nbsp; showWindow;

Sign In or Register to comment.