// =========================================================================== // 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. // =========================================================================== // centerReferencePivot.mel // // Callback to be used when creating a reference // Assumes message connections and an parenting have been done already // just does the final positioning // indicating the reference node // global proc centerReferencePivot (string $refNode) { $testNodes = eval("listConnections " + $refNode + ".associatedNode"); string $grpNode; string $locParent; // if we didn't group, nothing to do here if(size($testNodes) == 0) { select -cl; return; } // if there's 2 nodes, it's locator and group // and since we're doing this right after creation, we // think we know which is which if(size($testNodes) == 2) { $grpNode = $testNodes[0]; $locParent = $testNodes[1]; } else { $grpNode = $testNodes[0]; select -r $grpNode; } // center pivot on the grouped reference nodes xform -cp $grpNode; // if there was a locator, position it appropritately if(size($locParent) > 0) { string $locNodes[] = `listRelatives -typ locator $locParent`; string $locNode = $locNodes[0]; float $grpPivot[] = `xform -q -rp $grpNode`; setAttr ($locNode+".localPositionX") $grpPivot[0]; setAttr ($locNode+".localPositionY") $grpPivot[1]; setAttr ($locNode+".localPositionZ") $grpPivot[2]; xform -cp $locParent; string $actualAnnName = $refNode + "annotation"; string $actualTransform = `annotateLocator $locParent $refNode $actualAnnName`; // Indexes on the associatedNode attribute are used to make specific associations, // index 2 is reserved for the annotation node. connectAttr ($actualTransform + ".message") ($refNode+".associatedNode[2]"); select -r $locParent; } }