ScriptSpot

Forum topic · Scripts Wanted

Converting Maya script to 3ds max script.

By miauu · 2010-03-27

Description

Hello,

I was wondering if anyone might want to try and port this script from blender to max

----------------------------------------------------------------------------------

Simple script which lets a user select a couple of edges and it will continue the selection pattern around an edge ring or edge loop. To use: select two edges on either an edge ring or an edge loop and call selectEveryNEdge. This script should work on Maya 7 and up. I wouldn't call it "bullet proof" at the moment...ie. it's not perfect but should definitely be usefull.

Copy/Paste the following into a file named selectEveryNEdge.mel in you scripts folder.


proc int getEdgeIdIndex(int $edgeId, int $edgeIds[])
{
int $i;
int $len = `size($edgeIds)`;

for ($i=0; $i<$len; $i++)
{
if ($edgeId == $edgeIds[$i])
return $i;
}

return -1;
}

proc int getEdgeIdFromSelectionString(string $sel)
{
string $buffer[];
int $numTokens;
$numTokens = `tokenize $sel "[]" $buffer`;

if ($numTokens != 2)
return -1;
else
return $buffer[1];
}

global proc selectEveryNEdge()
{
string $selectedObject[] = `ls -sl -o`;

string $initialEdgeSelection[] = `getEdges`;
int $numEdges = `size $initialEdgeSelection`;
if (0 == $numEdges || 2 < $numEdges)
return;

string $firstEdge = $initialEdgeSelection[0];
int $firstEdgeId = getEdgeIdFromSelectionString($firstEdge);

if (1 == $numEdges) {
polySelect -edgeLoop $firstEdgeId $selectedObject[0];
return;
}

string $secondEdge = $initialEdgeSelection[1];
int $
clear $edgeLoopIds;
$edgeLoopIds = `polySelect -noSelection -edgeRing $firstEdgeId $selectedObject[0]`;

$firstEdgeIndex = getEdgeIdIndex($firstEdgeId, $edgeLoopIds);
if ($firstEdgeIndex == -1)
return;

$secondEdgeIndex = getEdgeIdIndex($secondEdgeId, $edgeLoopIds);
if ($secondEdgeIndex == -1) {
return;
}
}

int $numEdgesInLoop = `size($edgeLoopIds)`;
int $isFullLoop = ($edgeLoopIds[0] == $edgeLoopIds[$numEdgesInLoop-1]);

int $edgesToSkip = `abs ($secondEdgeIndex - $firstEdgeIndex)`;

if ($isFullLoop && $edgesToSkip > ($numEdgesInLoop - $edgesToSkip - 1)) {
$edgesToSkip = $numEdgesInLoop - $edgesToSkip - 1;
}

int $i;
string $selectionString = "select ";

for ($i=$firstEdgeIndex; $i<$numEdgesInLoop; $i += $edgesToSkip)
{
$selectionString += $selectedObject[0] + ".e[" + $edgeLoopIds[$i] + "] ";
}

for ($i=$firstEdgeIndex-$edgesToSkip; $i>=0; $i -= $edgesToSkip)
{
$selectionString += $selectedObject[0] + ".e[" + $edgeLoopIds[$i] + "] ";
}

eval($selectionString);
}

------------------------------------------------------------------------------