Oh yea, sorry for not explaining the script before I rushed to explaining the problem
The script is supposed to be a "smart" combine.
It combines the meshes the user has selected, deletes the old "trash nodes" that always gets left behind. It also renames the combined mesh into the name of the last selected item - and it's also supposed to move the mesh back to the group it originally were in (there will be an if-else statement to check if there is a group or not).
The result should be a combine that does not leave trash nodes, does not move the mesh to world, does not "ungroup" anything, etc.
So at the start it just stores the names of the group and the last selected object, combines them with polyUnite and renames it to the last selected item. The for-loop then takes care of all the trash nodes.
Everything works with it except that last part: It does NOT re-create the original group.
// Get last and first selected
string $lastName = `ls -sl -tail 1`;
string $allMeshes = `ls -sl`;
int $meshCount = `size($allMeshes)`;
// Get group name
string $root = rootOf($firstName);
polyUnite -ch 0 -mergeUVSets 1 -name $lastName;
// Delete old crap nodes
for ($obj in $allMeshes)
string $selected = $obj;
if ($selected != $lastName)
// save combined mesh into a var
string $selected = `ls -sl`;
// Recreate the group
group -name $root $selected;
...same problem though. Group is not created.