// =========================================================================== // 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: Dec, 2002 // // // // // // setConstraintRestPosition // // // None // // // Script for setting the rest position of a constrained object. // // The rest position is where a constrained object goes to when // the constraint is disabled (i.e. all weights equal zero). // // Say you have a cup constrained to a skeleton. At frame 10, you // want the skeleton to set the object on the table, where it will remain. // Go to frame 10, select the cup and call this method to set the // rest position. // // The constraint can now be disabled by setting its weight to 0, // and the cup will stay at its rest position. // //setConstraintRestPosition; // ///////////////////////////////////////////////////////////////////////// global proc setConstraintRestPosition() { string $sels[] = `ls -sl`; int $counter = 0; string $constraintTypes[] = { "pointConstraint", "aimConstraint", "orientConstraint", "scaleConstraint", "tangentConstraint", "normalConstraint", "parentConstraint" }; for ($constrainedObj in $sels) { // Find the constraint // for ($constraintType in $constraintTypes) { string $constrainAttr = ".rotate"; string $restAttr = ".restRotate"; string $queryCmd = ($constraintType + " -q "+$constrainedObj); string $constraint = `eval $queryCmd`; if ($constraintType == "pointConstraint") { $constrainAttr = ".translate"; $restAttr = ".restTranslate"; } else if ($constraintType == "scaleConstraint") { $constrainAttr = ".scale"; $restAttr = ".restScale"; } string $cmd; if (size($constraint)) { if ($constraintType != "parentConstraint") { float $currVal[] = `getAttr ($constrainedObj+$constrainAttr)`; $cmd = ("setAttr " + $constraint+$restAttr + " "); $cmd += ($currVal[0] + " " + $currVal[1] + " " + $currVal[2]); evalEcho $cmd; setAttr ($constrainedObj+$constrainAttr) $currVal[0] $currVal[1] $currVal[2]; $counter++; } else { float $currPos[] = `getAttr ($constrainedObj+".translate")`; float $currRot[] = `getAttr ($constrainedObj+".rotate")`; $cmd = ("setAttr "+$constraint+".restTranslate "); $cmd += ($currPos[0] + " " + $currPos[1] + " " + $currPos[2]); evalEcho $cmd; $cmd = ("setAttr "+$constraint+".restRotate "); $cmd += ($currRot[0] + " " + $currRot[1] + " " + $currRot[2]); evalEcho $cmd; setAttr ($constrainedObj+".translate") $currPos[0] $currPos[1] $currPos[2]; setAttr ($constrainedObj+".rotate") $currRot[0] $currRot[1] $currRot[2]; $counter++; } } } } if (0 == $counter) { error( (uiRes("m_setConstraintRestPosition.kAConstrainedObject")) ); } }