Namespaces in general are a bit difficult to work with as they tend to break scripts if you don't constantly check for them, so this trick is a simple and very useful way to check for them and prevent errors.
Let's say you have an object you want to select called, "r_hand_CTRL". You want to select it, but you need to test for namespaces because it might actually be named "Char:r_hand_CTRL" in your Maya scene. Or for more fun let's say it's named, "Post:Char:r_hand_CTRL".
Selecting r_hand_CTRL isn't going to work as it doesn't exist if it's prefixed with namespaces, so we have to search for what the namespaces are. Maya's namespace MEL commands are annoying and difficult to use. So here is a trick.
// Define Control
string $ctrl = "r_hand_CTRL" ;
// This int is used below to prevent an infinite loop
int $i = 0 ;
// Loop until it finds all the namespaces
// Stop at ten if it still can't find it
// Hopefully you don't have more than ten recursive namespaces
// May the Gods help you if you do.
// Check forever until the object exists, or $i = 10
while(!`objExists $ctrl` || $i == 10) {
// Append *: until it can find the object
$ctrl = ("*:"+$ctrl) ;
// Increment $i so we don't do this infinitely
$i++ ;
}
// Note: You could also use a FOR loop. But I didn't here.
// Now that we know $ctrl exists, we can do whatever we want with it
select -r $ctrl ;
I've already used this trick like forty times, it's awesome. Enjoy!
Edit: Since learning this, people have mentioned that you can just use the following command to find your object:
ls -recursive 1 "myObject" ;
Quite handy, and much more useful than what we worked on above! I wish I had the entire MEL docs memorized.... :)