// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: April 16, 2003 // // // // // // string rootOf(string $dagObject) // // // string : The root-level DAG parent of the specified DAG object. // // // This procedure returns the name of the root-level DAG parent of the // specified object, if any. If the specified object has no parents, the // return value is "". // // See also firstParentOf(). // // // string $dagObject The object whose root-level DAG parent should be returned. // // // // Create a NURBS sphere. // // // string $createdNodes[] = `sphere -constructionHistory false`; // string $sphere = $createdNodes[0]; // // // Create a group containing a group containing the sphere. // // // string $group1 = `group`; // string $group2 = `group`; // // // Use rootOf() to get the root of the sphere. This should be // // the name of the second group. // // // string $rootOfSphere = rootOf($sphere); // // if (isSameObject($group2, $rootOfSphere)) print("// Success!\n"); // // Success! // global proc string rootOf(string $dagObject) { // // Description: // This procedure returns the name of the root-level parent of the // specified DAG object. // string $root = ""; if ($dagObject != "") { if (`objExists $dagObject`) { if (size(`ls -dagObjects $dagObject`) > 0) { for (;;) { string $parents[] = `listRelatives -parent -fullPath $dagObject`; if (size($parents) == 0) { $root = longNameOf($dagObject); break; } $dagObject = $parents[0]; } } else // (size(`ls -dagObjects $dagObject`) == 0) { string $fmt = (uiRes("m_rootOf.kNotADAGNode")); error `format -s $dagObject $fmt`; } } else // (!`objExists $dagObject`) { string $fmt = (uiRes("m_rootOf.kNoDAGNode")); error `format -s $dagObject $fmt`; } } return $root; }