PDA

View Full Version : vertex number


fbitonti
12-28-2006, 01:03 AM
This is most likley a simple question but what I am trying to do is query the index number of the vertex.

for example:
in
"polySurface2.vtx[1]"
how do return only the "1".

like i said most likley a studip question but please help I'm racking my brain.

Hoju
12-28-2006, 01:39 PM
Hi fbitonti

The only way that I know how to get around this, as of version 7.0, is to use the tokenize command. Here is a procedure that should work for you.

proc int getVertIndex(string $rawVertIndex)
{
//Variables
string $buffer1[];
string $buffer2[];
int $index;

tokenize $rawVertIndex "]" $buffer1;
tokenize $buffer1[0] "[" $buffer2;
$index = $buffer2[1];

return $index;
};

run the procedure, then you can enter in this example.

getVertIndex("polySurface2.vtx[1]");

I hope this helps.:)

wdavidlewis
12-29-2006, 10:05 PM
You can also do this with two calls to match:

proc int getVertIndex(string $rawVertIndex)
{
string $bracketedIndex = `match "\[[0-9]+\]" $rawVertIndex`;
return `match "[0-9]+" $bracketedIndex`;
}


with the first match call getting the index with the brackets and the second one stripping the brackets off.

I'm not sure whether this way is faster then the calls to tokenize. In this version, you don't need the arrays, but you have to setup the regular expressions. Six of one... probably.

BTW, I tried to get this to work with 'substitute', but I can't get substitute to handle ['s in the regular expression even though I'm quoting them with a \. Wonder if it's a bug in the in the r.e. code for substitute (though it works for match and you'd think they'd share the r.e. code...)

--- David

sunit
12-30-2006, 02:56 AM
double post. see below.

sunit
12-30-2006, 02:56 AM
you can actually achieve this with one tokenize call:


proc int getVertIndex( string $rawVertIndex )
{
string $buffer[];
tokenize $rawVertIndex "[]" $buffer;
return $buffer[ size($buffer) - 1 ];
}


there's also a great discussion on using substitute with reg exp in maya7+ here:

http://www.highend3d.com/boards/index.php?showtopic=213550&st=15

-sunit

CGTalk Moderation
12-30-2006, 02:56 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.