// =========================================================================== // 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. // =========================================================================== // loadRelatedReference.mel // // If we have the locator or annotation associated with // a reference node, we can unload the reference. // global proc string getRelatedReference ( string $relNode ) { if( `reference -q -isNodeReferenced $relNode`) { string $fileName = `reference -q -filename $relNode`; string $refNode = `file -q -rfn $fileName`; return $refNode; } // if we're lucky this is already the locator parent string $testNodes[] = `listConnections $relNode`; string $testNode; int $refFound = 0; for ($testNode in $testNodes) { if (`nodeType $testNode` == "reference" ) { return $testNode; } } string $testParents[]; string $testChildren[] = `listRelatives -fullPath -shapes $relNode`; // We may have selected the main scene parent of an instanced // referenced shape. // for ( $testNode in $testChildren ) { if( `reference -q -isNodeReferenced $testNode`) { string $fileName = `reference -q -filename $testNode`; string $refNode = `file -q -rfn $fileName`; return $refNode; } } // perhaps we were over the annotation instead // If this is a grouping structure like we created when // doing a reference with locator, this will find the right ref // If not, it will just muddle around the dg a bit more before failing if(size($testChildren) > 0) { if(`nodeType $testChildren[0]` == "annotationShape") $testParents = `listRelatives -fullPath -parent $relNode`; } if(size($testParents) > 0) { $testNodes = `listConnections $testParents[0]`; for ($testNode in $testNodes) { if (`nodeType $testNode` == "reference" ) { return $testNode; } } } // It's possible that the user had right moused over nothing // with the locator or annotationshape already selected // but we'll worry about that later return ""; }