MEL How-To #44

Back · Previous · Next Maya

How do I expand a polygon component selection to include all components in the same shell?

By using the polySelectConstraint command you can select connected components, components within a shell, or components on open borders.

It was previously reported on these pages that you had to use a recursive "brute force" method to expand the selection to include the full shell. This is not true.

The key lies in the ‘−type’ flag. You must specify the ‘−type’ flag to apply an "All & Next" constraining selection.

The following MEL will select all polygon face components within the same "shell" as the current selection:

ls -sl;
// Result: pCube1.f[5] //

// type 0x0008 is facet
// mode 3 is "All&Next"
polySelectConstraint -type 0x0008 -shell true -mode 3;

ls -sl;
// Result: pCube1.f[0:5] //

The starting selection need not be a face component:

ls -sl;
// Result: pCube1.e[9] //
polySelectConstraint -type 0x0008 -shell true -m 3;
ls -sl;
// Result: pCube1.f[0:5] //

ls -sl;
// Result: pCube1.f[5] //
// Select all vertices is same shell
polySelectConstraint -type 0x0001 -shell true -m 3;
ls -sl;
// Result: pCube1.vtx[0:7] //

Note: This command enables a global constraining selection mode that affects the UI. If you leave the user in this mode then everytime they select one or more components the selection will be expanded to include the entire shell. Thus, you should reset the selection contraints by turning off all modes that you turn on. In this example that would be the ‘−shell’ flag:

// Reset -shell selection constraints
polySelectConstraint -shell false;

Be aware that if the constraint results in UVs being selected you will receive repeated "Some items cannot be moved/rotated/scaled" warnings if any of the Sacred Tools are active. You can get around this by temporarily activating the Select Tool, performing the selection and then resetting the previously active Sacred Tool:

global string $gSelect;
string $currentCtx = `currentCtx`;
setToolTo $gSelect;

// ... UV selection stuff here ...

setToolTo $currentCtx;

29 August 2002