Hey David,
it might be smart just to get in and start learning the basics of mel. The Echo all commands is something that can help you with that but it can also confuse you.
Since you will be using mel a lot i suggest bookmarking this page :
file:///C:/Program%20Files/Autodesk/Maya2011/docs/Maya2011/en_US/Commands/index.html
(the path can differ depending on your maya version. )
As for your question. There is not a simple way to reverse (swap) the order of an array around in mel. You would have to use a for loop.
But that might be a bit too much for now. In case you are still interested take a look here:
http://forums.cgsociety.org/archive/index.php/t-190195.html
But sometimes the solution is more simple than you might think. If you have a selection array you can also just get the last or first object in the array.
for example:
// make a simple array
$myStringArray = {"pos 0","pos 1","pos 2","pos 3"}
// ask the value at an index nr of the array (mind that an array starts counting at 0)
print $myStringArray[0]
we can also get the total index size of the array. With this information we can get the last object in our selection since we will not always know how big our selection is going to be.
$araySize = size($myStringArray)-1;
Mind the -1 !!!
The value that the size function gives you starts counting at 1! so if you would want to use that value in the array again you need to substract 1.
so now we can get the last object in our array.
print $myStringArray[$araySize]
Here is a simple example of how you could use it for your purpose.
// simple procedure for constraining objects.
proc myConstrainFunction(int $firstBool){
string $mySelection[] = ls -sl;
// get the number of selected objects
$araySize = size($mySelection)-1;
string $firstObject;
// simple if check to see if we need to find the last or the first object in our selection
if ($firstBool){
$firstObject = $mySelection[0];
stringArrayRemoveAtIndex(0, $mySelection);
}else{
$firstObject = $mySelection[$araySize];
stringArrayRemoveAtIndex($araySize, $mySelection);
}
pointConstraint -offset 0 0 0 -weight 1 $mySelection $firstObject;
}
Now select your objects in the scene (it does not matter how manny objects you have).
If you give the procedure a 1 as argument (The value between the brackets) the first object in your selection will be constraint to the other objects with a point constraint.
If you put a 0 as argument the last object in your selection will be constrained to the other objects.
myConstrainFunction(1);
This should give you enough to play around with ^^.