Use the objExists mel command.
First let's use it in a simple way to check for the existence of an object saved in $myObject
// objExists will return true or false (1 or 0), so you can use it multiple ways.
int $objTest = `objExists $myObject` ;
// If that object exists, it will return 1 (true), so then you could say something like:
if($objTest == 1) {
print "It Exists!" ;
}
// Another trick you can do is an IF statement will simply test a boolean (true or false) and fire if it's true, example:
if($objTest) {
print "It Exists!" ;
}
// So using that, we can simply test for the return of objExists in our IF statement, to simplify it even more.
if(`objExists $myObj`) {
print "It Exists!" ;
}
This works for attributes too, so to check for the existence of an attribute on a certain object, let's say "R_Arm_Ctrl.IKFK" we can use the following:
if(`objExists "R_Arm_Ctrl.IKFK"`) print "It Exists!" ;
Huzzah!