Despite the name, the ‘select’ command is NOT your main command here! The easiest way to select objects by type in MEL is through the ‘ls’ command. It doesn’t actually select anything, but it lists filtered objects. Then you can loop through the list and select each object therein.
‘Ls’ actually already has a few common types listed as flags, so if you want to list all of the lights in your scene, for example, all you have to do is add the -lights flag to the command.
But say you want a list of objects that aren’t so common, like a particular mental ray shader or a self-created node. We have to get a bit fancier. There are a couple of ways to do this:
1) Use ‘ls’ with a -type flag
This can get funky though… sometimes Maya lists objects as ‘untyped’. You can also try the -exactType or -exludeType flags.
2)If you want to make SUPER SURE that you’re getting every instance of an SPECIFIC type, you can specify using the nodeType command in a loop. Please note that this is for SPECIFIC (see, I capitalized and repeated it) types, like ‘mia_material_x’, not something more general like ‘surfaceShape’ or ‘transform’. And here’s where ‘select’ finally comes into play! The -a flag on it just adds each new filtered object to the list. Simple and easy!
//This script selects all Mental Ray MIA Material X nodes. // global proc selectAllMIAx() { string $allTexs[] = `ls -l`; string $eachTex; for ( $eachTex in $allTexs) { if ( `nodeType $eachTex` == "mia_material_x" ) { print ($eachTex + "\n"); select -add $eachTex; } } }