Adding new items to an array is a bit cluncky in MEL.
This way is a bit more efficient:
//Get mesh name
string $meshName[] = `ls -sl`;
//Get long attribute names
string $attrLongName[] = `listAttr -userDefined $meshName[0]`;
//Set up arrays and counters
string $attrNiceName[] = {};
//Loop to get nice names
for ($item in $attrLongName)
{
string $niceName = `attributeName -n ($meshName[0] +"."+ $item)`;
//Append to array
$attrNiceName[size($attrNiceName)] = $niceName;
//Print contents
print $attrNiceName;}
Also if you want to allow multi-selection it would look like this:
//Get mesh name
string $meshNames[] = `ls -sl`;
string $attrNiceName[] = {};
for ($mesh in $meshNames){
//Get long attribute names
string $attrLongName[] = `listAttr -userDefined $mesh`;
//Set up arrays and counters
//Loop to get nice names
for ($item in $attrLongName)
{
string $niceName = `attributeName -n ($mesh +"."+ $item)`;
//Append to array
$attrNiceName[size($attrNiceName)] = $niceName;
//Print contents
print $attrNiceName;}
}
I hope it helps!