Can mel perform same action on many objects

How can I write a mel script that will allow me to perform an action to all selected groups
seperately? For example, I select 9 diferent objects, and would like to group each one to itself.
If I were in a C shell I could do something like: foreach f (*);group $f ;end - if that helps any.
Thanks!

// script to group each object selected to itself.
// select groups at end.
string $selObj[];
string $groups[];
string $obj;
string $newGroup;
$selObj = ls -sl;
for ($obj in $selObj) {
$newGroup = group -n ($obj+"\_Group") $obj;
$groups[(size($goups)] = $newGroup;
}
select $groups;

the script works fine the first time, but it seems the
variables don't clear themselves out. The second
hit starts producing errors.
how can I erase what's in the string?

Edited by mbfor on 04/10/01 01:42:17 PM.

Add

{
...script
}

and maya will discard all the variable inside the { } after that the script has been executed.

or another way is using: cleat $varName but I strongly raccomand to use the { } in your script edito otherwise all the variable that you use are considere globals.

Hope this help,

-a

global proc groupSelected() {
// script to group each object selected to itself.
// select groups at end.
string $selObj[];
string $groups[];
string $obj;
string $newGroup;
$selObj = ls -sl;
for ($obj in $selObj) {
$newGroup = group -n ($obj+"\_Group") $obj;
$groups[(size($goups)] = $newGroup;
}
select $groups;
}

// now to use it, just call "groupSelected" (no quotes)
// better yet, drag the command from the script editor to the shelf, and just click it every time.