|
global proc int[] getSelectedIndices()
{
int $indices[];
int $count = 0;
int $n, $j;
string $items[];
string $vertexStrs[] = `ls -sl`;
// Check for a valid selection
if(size($vertexStrs) == 0)
return $indices;
for($n = 0; $n < size($vertexStrs); $n++) {
// The regular expression says, "find one or more digits
// followed by a colon followed by one or more digits".
string $range = `match "[0-9]+:[0-9]+" $vertexStrs[$n]`;
// We've found a pair of numbers, for example, "15:19"
if($range != "") {
// Split the pair into two strings
tokenize($range, ":", $items);
// Convert the strings to the first and last index
// in the range ie. integer 15 and 19
int $beginIndex = $items[0];
int $endIndex = $items[1];
// Check we have valid index values
if($endIndex > $beginIndex) {
for($j = 0; $j <= ($endIndex - $beginIndex); $j++) {
// Add the index to the output list
$indices[$count] = $beginIndex + $j;
$count++;
}
}
}
else // ...its just a single integer
{
// The next regular expression says, "find an open
// square bracket followed by one or more digits followed
// by a closing square bracket".
string $indexStr = `match "\[[0-9]+\]" $vertexStrs[$n]`;
// extract the digits ie. ignore "[" and "]"
$index = `substring $indexStr 2 (size($indexStr)-1)`;
$indices[$count] = $index;
$count++;
}
}
return $indices;
}
|
After selecting a few vertices of a poly sphere
the command,
ls -sl
might return the following information.
pSphere1.vtx[265]
pSphere1.vtx[284:285]
pSphere1.vtx[302:304]
Notice the last two items provide a range of indices separated by colons.
Using the proc shown opposite, for example,
int $result[] = getSelectedIndices();
we obtain an array of "extracted" index values ie,
265 284 285 302 303 304
|