MEL How-To #98 | ||
| ||
How do I determine if an object is visible?A "cheap" test for visibility would be to simply test a node's '.visibility' attribute; however, this would not be entirely accurate. There are other factors to consider:
The following MEL procedure shows a method for querying a node's visibility: proc int nodeIsVisible( string $node ) { // If user is asking about a bogus node, return FALSE. if ( !`objExists $node` ) return false; // Object must be a DAG node, or it's not visible. // There's no MEL query to identify a DAG node, but the kDagNode class adds // the '.visibility' attribute, so we'll use its existence as a cue. if ( !`attributeQuery -node $node -exists "visibility"` ) return false; // The obvious: Start with the '.visibility' attribute on the node. int $visible = `getAttr ( $node + ".visibility" )`; // If this is an intermediate mesh, it's not visible. if ( `attributeQuery -node $node -exists "intermediateObject"` ) { $visible = $visible && !`getAttr ( $node + ".intermediateObject" )`; } // If the object is in a displayLayer, and the displayLayer is hidden, // then the object is hidden. if ( `attributeQuery -node $node -exists "overrideEnabled"` && `getAttr ( $node + ".overrideEnabled" )` ) { $visible = $visible && `getAttr ( $node + ".overrideVisibility" )`; } // Ascend the hierarchy and check all of the parent nodes. if ( $visible ) { string $parents[] = `listRelatives -parent $node`; if ( `size $parents` > 0 ) { $visible = $visible && nodeIsVisible( $parents[0] ); } } return $visible; } 11 Apr 2004 | ||
Copyright ©2005 by Bryan Ewert, maya@ewertb.com Maya is a Registered Trademark of Alias |