MEL How-To #54

Back · Previous · Next Maya

How do I get an expanded list of selected components instead of the default "range" format?

Typically Maya returns a list of selected components using its "range" format where an index sequence is compressed to "[start:end]".

ls -sl;
// Result: pSphere1.f[73:76] //

There are several methods you can use to retrieve a fully expanded list.

ls

In Maya v3 a −flatten flag was added to the ‘ls’ command:

ls -sl -flatten;
// Result: pSphere1.f[73] pSphere1.f[74] pSphere1.f[75] pSphere1.f[76] //

The −flatten flag can also be used to expand an arbitrary selection list:

string $adjacentComponents[] = { "pSphere1.f[26:27]", "pSphere1.vtx[1:3]" };
// Result: pSphere1.f[26:27] pSphere1.vtx[1:3] //

ls -flatten $adjacentComponents;
// Result: pSphere1.f[26] pSphere1.f[27] pSphere1.vtx[1] pSphere1.vtx[2] pSphere1.vtx[3] //

Note that items in your arbitrary list must actually exist within the current scene, else the ‘ls’ command will not include them in its result array.

filterExpand

The ‘filterExpand’ command returns a string array of selected components and offers an −expand option. You must also include one or more −selectionMask flags to specify which component type you require:

filterExpand -selectionMask 34 -expand true;
// Result: pSphere1.f[73] pSphere1.f[74] pSphere1.f[75] pSphere1.f[76] //

29 August 2002