Testing the existence of commands, objects, and attributes

 
 
 

Commands and scripts: exists

The exists command returns true if the argument is a valid command, subroutine, or script.

if (exists("sphere")) {
	sphere; // make a sphere
}

objects: objExists

The objExists function returns true when an object exists with a certain name:

sphere -name "george";
// Result: george makeNurbSphere1 //
print(objExists("george"));
1
print(objExists("martha"));
0

attributes on nodes: attributeExists

Use attributeExists to check whether a given attribute exists on a node. The command has the form:

attributeExists("attributeName","nodeName")

For example:

if (attributeExists("visibility","mySphere")) {
	setAttr mySphere.visibility on;
}

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License