PDA

View Full Version : querying vertex id number


golden14
04-11-2006, 11:35 AM
I'm having a problem where I would like to select a vertex and query its ID number. For example, if I were to select a vertex on an object, in the script editor it would appear as object.vtx[#]. how can i query just that number, so i can then assign it to a variable and use it to select that particular vertex number on other copies of that object?

Any help would be greatly appreciated. Thanks,

- Shay

Robert Bateman
04-11-2006, 12:10 PM
$items = `ls -sl -fl`;
for( $i in $items )
{
string $out_buffer[];
$nTokens = `tokenize ($i) "[]." $out_buffer`;
if($nTokens>2) {
int $vertexIDX = $out_buffer[2];
print( " " + $out_buffer[0] + " " + $out_buffer[1] + " " + $vertexIDX + "\n" );
}
}

golden14
04-11-2006, 07:57 PM
Thank you for replying so quickly. The code you posted works....sort of. I select a vertex and then run the code you wrote. It then gives me an error saying:

"// Error: line 5: Invalid call to "tokenize". Check number and types of arguments expected by the procedure. //"

But when I run the code a second time (without even deselecting and reselecting the vertex), it works. I was wondering why it wont work the first time but it will the second time?

Thanks,

- Shay

golden14
04-12-2006, 03:59 PM
Ok, so I realized why it was giving that error. I needed to delcare $items as a string and an array. Once I do that, it works. What I'm still a little confused about though, is why I need the for loop in there. When I try taking it out, the code doesnt work and gives me the same error I had before. I'm only reading in one object for it tokenize though, so I dont really get why it needs to be put into a loop. Here is the code that I got to work:

string $items[] = `ls -sl -fl`;
for( $i in $items )
{
string $out_buffer[];
tokenize ($i) "[]." $out_buffer;
print $out_buffer[2];
}


So basically, I'm just wondering why the for loop is needed. Thanks,

- Shay

Robert Bateman
04-12-2006, 04:38 PM
because ls -sl returns the current selection, and it's likely hat you have more than one thing selected, which is why it returns an array. The loop is used to iterate over each item in the array (in this case, each selected vertex).

golden14
04-12-2006, 04:55 PM
Ok, so it has to do with the ls -sl command. That makes sense. Thanks for all your help.

CGTalk Moderation
04-12-2006, 04:55 PM
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.