PDA

View Full Version : non-string array tools in MEL ?


Exo7
11-29-2011, 04:57 PM
It strikes me down that I didn't notice this presumed lack earlier, but are there such generic commands like the stringArray* serie, for float arrays ?

Presently I am interested in the stringArrayRemoveAtIndex functionality, having an array of floats I would like to remove either the first or second elements depending on wich is greater. Here's what I have currently:

proc float getMaxArrayValue(string $vArray[])
{
int $remove;
do
{
float $value0 = $vArray[0];
float $value1 = $vArray[1];
$remove = $value0>$value1;
stringArrayRemoveAtIndex($remove, $vArray);
}
while(size($vArray)>1);

return $vArray[0];
}
getMaxArrayValue {"6","3","7","9","5","2","4","1","0","8"};
// Result: 9 //
As you can see the proc is taking a string array as argument and outputs one float value. How would I get the same output with a float array as argument ?

Specifically, what would the equivalent be for this line:
stringArrayRemoveAtIndex($remove, $vArray);

mlefevre
11-29-2011, 07:30 PM
If you want the highest value in a float array, this should work. Python would be much better for these sorts of tasks though.

global proc float getMaxArrayValue(float $vArray[])
{
$vArray = sort($vArray);
return $vArray[size($vArray)-1];
}

NaughtyNathan
11-29-2011, 08:26 PM
stringArrayRemoveAtIndex and all the other stringArray.. commands are just MEL script files in the Maya\others\ folder. if you copy stringArrayRemoveAtIndex.mel and edit it (changing all the string to float) you'll have your self a floatArrayRemoveAtIndex command.

:nathaN

Exo7
11-29-2011, 08:32 PM
I am realizing that I have almost exclusively been working with strings arrays for this reason.

I realised because I never used the sort command, thank you for the tip !

I see it is under the same documentation section than the stringArray* serie (Language) and works also on strings arrays, I'll dig deeper around those thanks.

Either what I am thinking that converting back and forth the array type is the most convenient solution although certainly not the most computationally efficient.

I am strongly considering python. Nearly staring at it ;)

CGTalk Moderation
11-29-2011, 08:32 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.