// This script will make a linear curve feom a row of selected edges... // A few rules... // 1: Make sure all the selected edges are contiguous with no gaps. // 2: You cant make a line that has no begniing or end. For example a closed loop. Make sure there is a starting point and an end point. // 3: Cross your fingers global proc makeCurveFromEdges() { // Collect all the data we need... string $parent[] = `listRelatives -p`; $parent = `listRelatives -p $parent[0]`; string $obj = $parent[0]; string $lssl[] = `ls -sl`; string $allEdges[] = `filterExpand -sm 32`; PolySelectConvert 3; string $allVerts[] = `ls -sl`; select -cl; float $curvePointLoc[]; string $testVerts[]; string $lastEdge; string $lastVert; string $nextEdge = `re_findTheFirstEdge $allEdges`; // Start looping through the edges starting with the one at the beginning of the selected line for ($i = 0; `size($allEdges)` > $i; ++$i) { int $verts[] = `re_returnSharedVerts $nextEdge`; $lastEdge = $nextEdge; for ($ii = 0; 2 > $ii; ++$ii) { string $fullVertPath = ($obj+".vtx["+$verts[$ii]+"]"); if($fullVertPath != $lastVert) { int $edges[] = `re_returnSharedEdges $fullVertPath`; for ($iii = 0; `size($edges)` > $iii; ++$iii) { string $fullEdgePath = ($obj+".e["+$edges[$iii]+"]"); for ($iiii = 0; `size($allEdges)` > $iiii; ++$iiii) { if($fullEdgePath == $allEdges[$iiii] && $fullEdgePath != $lastEdge) { $nextEdge = $fullEdgePath; break; } } } $testVerts[`size($testVerts)`] = $fullVertPath; $lastVert = $fullVertPath; break; } } } string $curveStart = "curve -d 1"; string $curve; // Now that we have the ordered list of verts lets go through and get their positions and draw a curve... for ($i = 0; `size($testVerts)` > $i; ++$i) { float $loc[] = `xform -q -ws -t $testVerts[$i]`; $curve += (" -p "+ $loc[0] +" "+ $loc[1] +" "+ $loc[2]); } string $curveCmd = ($curveStart+$curve); eval $curveCmd; } // Return All Verts that are connected to the input edge global proc int[] re_returnSharedVerts(string $edge) { int $out[]; string $edgeVerts[] = `polyInfo -ev $edge`; string $buffer[]; $numTokens = `tokenize $edgeVerts[0] " " $buffer`; $out[0] = $buffer[2]; $out[1] = $buffer[3]; return $out; } // Return All Edges that are connected to the input vertex global proc int[] re_returnSharedEdges(string $vert) { int $out[]; string $edgeVerts[] = `polyInfo -ve $vert`; string $buffer[]; $numTokens = `tokenize $edgeVerts[0] " " $buffer`; for ($i = 2; (`size($buffer)`-1) > $i; ++$i) { $out[`size($out)`] = $buffer[$i]; } return $out; } // Return the edge that is on the edge of the selected line. This is used as the starting point. global proc string re_findTheFirstEdge(string $edges[]) { string $out; string $parent[] = `listRelatives -p $edges[0]`; $parent = `listRelatives -p $parent[0]`; string $obj = $parent[0]; for ($i = 0; `size($edges)` > $i; ++$i) { int $verts[] = `re_returnSharedVerts $edges[$i]`; for ($ii = 0; `size($verts)` > $ii; ++$ii) { string $fullVertPath = ($obj+".vtx["+$verts[$ii]+"]"); int $sharedEdges[] = `re_returnSharedEdges $fullVertPath`; int $count; $count = 0; // Loop Through All Edges Associated with this vertex for ($iii = 0; `size($sharedEdges)` > $iii; ++$iii) { string $fullEdgePath = ($obj+".e["+$sharedEdges[$iii]+"]"); for ($iiii = 0; `size($edges)` > $iiii; ++$iiii) { if($fullEdgePath == $edges[$iiii]) { $count +=1; } } } if ($count == 1) { return $edges[$i]; } } } return $out; }