How to reverse an array on mel script ??


Hello everybody,
that’s my first post on CGtalk. I just begin to play with the mel script and I would like to know if there’s a function who can reverse an array. Here’s an example :

string $alphabet[] = {“a”, “b”, “c”, “d”};
[color=White]print $alphabet;
// result a b c d[/color]
ReverseArray [color=White]$alphabet;
print $alphabet;
// result d c b a

In this example [color=Red]ReverseArray doesn’t exist so I looking for the real name of this function.
For the moment I use a for and a second array to reverse $alphabet but a hope this function exist.
Thank’s a lot.

global proc string[] zooUtilsReverseArray( string $array[] ){
 	string $reversedArray[];
 	int $arraySize = `size $array`;
 	for( $n = 0; $n < $arraySize; $n++ ) $reversedArray[( $arraySize - 1 - $n )] = $array[$n];
 	return $reversedArray;

if you have the zooUtils script then you alreay have this function available. otherwise, use that code.


Thanks for the information macaroniKazoo,
It’s quite the same script I made but yours is optimized :slight_smile:
here’s mine :

string $alphabet[] = {"a", "b", "c", "d", "e", "f", "g"};
    string $tebahpla[];
    int $o = size($alphabet)-1;
    int $i;
    for ($i=0; $i < size($alphabet); $i++) {
        $tebahpla[$i] = $alphabet[$o];
I will download this tool, it seems to be interresting.

Thanks a lot.


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.