You are on page 1of 11

lockdown - A script from another place. copywrite blah blah....

Lock stuff in place


most of the time. And it's super easy. Make it a button on your shelf.

//
//Added the auto "Range Fwd and Rev" Lock.
//will lock down the selected object based on the Hilighed Time Range Slider.

// This script will lock down, hold and key an object to world space for x amount
of frames for the current object position

// Select the object to lock down and hold

// Enter the amount of frames to hold

// This script will create a locator snaps it to current selection//

// Select locator and add to isolation panel//

// Select the first selected object and lock it down to the new locator//

// Then key the first selected object x amount of frames

// Then remove the created locator

// ******UI********

global proc fabLockDownUI()

//kill existing
if ((`window -ex frameyWindow`) == true) deleteUI frameyWindow;

//create UI
window -w 4 -t "Lock Down v2" frameyWindow;

rowLayout -numberOfColumns 5 -cw5 60 60 80 98 100;


intField -minValue -1000 -maxValue 1000 -value 0 lockFrames;
button -l "Lock Fwd" -c "lockDown(`intField -q -v lockFrames`)" doButton1;
button -l "Lock Rev" -c "lockDownRev(`intField -q -v lockFrames`)"
doButton2;
button -l "Lock Range Fwd" -c "lockRangeFwd" doButton3;
button -l "Lock Range Rev" -c "lockRangeRev" doButton4;
window;

showWindow frameyWindow;

global proc lockDown(int $holdFrames){

//Declare some vairables


string $timeIn = `currentTime -q`;

string $locator[];

//Create selection list

string $sel[]=`ls -sl`;

//the first object in the array

string $firstObject = $sel[0];

//Create locator

$locator = `spaceLocator -name ("Snap_to_" + $firstObject)`;

//Get the rotation values of first object

float $rot[]=`xform -q -ws -rotation $firstObject`;

//Assign the rotation values on to the locator

xform -ws -rotation $rot[0] $rot[1] $rot[2] $locator;

//Get the translation values of first object

float $trans[]=`xform -q -ws -rp $firstObject`;

//Assign the translation values on to the locator

move -rpr $trans[0] $trans[1] $trans[2] $locator;

//isolate the locator

select $locator;

isolateSelect -addSelected modelPanel1;

isolateSelect -addSelected modelPanel2;

isolateSelect -addSelected modelPanel3;


isolateSelect -addSelected modelPanel4;

select -cl ;

select -r $firstObject ;

select -tgl $locator;

//---------------------------------------------------------//

//lock down and hold

int $i=0;

while($i<$holdFrames)

float $trans[]=`xform -q -ws -rp $locator`;

float $rot[]=`xform -q -ws -rotation $locator`;

xform -ws -rotation $rot[0] $rot[1] $rot[2] $firstObject;

move -rpr $trans[0] $trans[1] $trans[2] $firstObject;

setKeyframe $firstObject.t;

currentTime ( `currentTime -q` + 1 );

$i = $i + 1;

select -cl ;

select $locator;

delete;

select $firstObject;

global proc lockDownRev(int $holdFrames){

//Declare some vairables


string $timeIn = `currentTime -q`;

string $locator[];

//Create selection list

string $sel[]=`ls -sl`;

//the first object in the array

string $firstObject = $sel[0];

//Create locator

$locator = `spaceLocator -name ("Snap_to_" + $firstObject)`;

//Get the rotation values of first object

float $rot[]=`xform -q -ws -rotation $firstObject`;

//Assign the rotation values on to the locator

xform -ws -rotation $rot[0] $rot[1] $rot[2] $locator;

//Get the translation values of first object

float $trans[]=`xform -q -ws -rp $firstObject`;

//Assign the translation values on to the locator

move -rpr $trans[0] $trans[1] $trans[2] $locator;

//isolate the locator

select $locator;

isolateSelect -addSelected modelPanel1;

isolateSelect -addSelected modelPanel2;

isolateSelect -addSelected modelPanel3;


isolateSelect -addSelected modelPanel4;

select -cl ;

select -r $firstObject ;

select -tgl $locator;

//---------------------------------------------------------//

//lock down and hold

int $i=0;

while($i<$holdFrames)

float $trans[]=`xform -q -ws -rp $locator`;

float $rot[]=`xform -q -ws -rotation $locator`;

xform -ws -rotation $rot[0] $rot[1] $rot[2] $firstObject;

move -rpr $trans[0] $trans[1] $trans[2] $firstObject;

setKeyframe $firstObject.t;

currentTime ( `currentTime -q` - 1 );

$i = $i + 1;

select -cl ;

select $locator;

delete;

select $firstObject;

//Forward Locks down the number of frames based on the highliged selection in the
Time Slider
//Locking will occur based on the FIRST frame of the highliged section
global proc lockRangeFwd(){
global string $gPlayBackSlider;
float $rangeArray[2];
$rangeArray = `timeControl -q -rangeArray $gPlayBackSlider`;
currentTime ($rangeArray[0]);
$frameCount =($rangeArray[1] - $rangeArray[0]);
lockDown($frameCount);
}

//Reverse Locks down the number of frames based on the highliged selection in the
Time Slider
//Locking will occur based on the LAST frame of the highliged section

global proc lockRangeRev(){


global string $gPlayBackSlider;
float $rangeArray[2];
$rangeArray = `timeControl -q -rangeArray $gPlayBackSlider`;
currentTime ($rangeArray[1]);
$frameCount =($rangeArray[1] - $rangeArray[0]);
lockDownRev($frameCount);
}

fabLockDownUI;

tt -assign to a key. It the tungten tangent tool. It's on the graph editor. But
having it as a hotkey saves time.

proc float shallower(float $value1, float $value2)


{return ( abs($value1) < abs($value2) ) ? ($value1) : ($value2);}

proc float steeper(float $value1, float $value2)


{return ( abs($value1) > abs($value2) ) ? ($value1) : ($value2);}

global proc trdprty_tungsethTangent()


{
// Declare variables:
int $numberofcurves; int $c; string $curve; int $I;
int $selectedindexes; int $totalindexes;
int $start; int $end;
string $tanType; string $step; int $locked;
int $i[5]; float $x[5]; float $y[5]; float $m[4];
//string $before; string $keynode; string $after;
int $sign[4]; int $node;
float $ix; float $ox;
float $inSmooth; float $outSmooth; float $inlimit; float $outlimit;
float $inSlope; float $outSlope; float $inAngle; float $outAngle;
int $locked; int $weighted; int $weightlock; float $inweight; float $outweight;
float $smooth; float $limit;
float $slope; float $angle;

waitCursor -state on; // make a nice wait cursor icon while it works...-comet

// Outer loop goes through selected curves, one at a time.


string $curves[] = `keyframe -q -sl -name`;
$numberofcurves = `size ($curves)`;
for ($c = 0; $c < $numberofcurves; $c = $c + 1)
{

// Inner loop goes through selected keys, one at a time.


$curve = $curves[$c];
int $selectedindexes[] = `keyframe -query -sl -iv $curve`;
$totalindexes = `keyframe -q -kc $curve`;
$numberofselectedindexes = `size ($selectedindexes)`;
for ($I = 0; $I < $numberofselectedindexes; $I = $I + 1)
{

// Determine index value of current key (2) and four neighbors (0,1,3,4).
$i[2] = $selectedindexes[$I];
$i = {$i[2] - 2, $i[2] - 1, $i[2], $i[2] + 1, $i[2] + 2};

//if tangency type is not "step", do the following.


string $tanTypes[] = `keyTangent -in $i[2] -q -ott $curve`; $tanType =
$tanTypes[0];
$step = "step";
if ($tanType != $step)
{

// Loop to determine x and y positions of five keys (time and value of each).
$start = (`max 0 (2 - $i[2])`);
$end = (`min 5 (2 + $totalindexes - $i[2])`);
for ($p = $start; $p < $end; $p = $p + 1)
{
float $X[] = `keyframe -in $i[$p] -query -tc $curve`; $x[$p] = $X[0];
float $Y[] = `keyframe -in $i[$p] -query -vc $curve`; $y[$p] = $Y[0];
}

// Calculate four slopes between the keys (0,1,2,3).


for ($p = 0; $p < 4; $p = $p + 1)
{
if ($p < $start || $p > ($end - 2))
{$m[$p] = 0.0;}
else {$m[$p] = ($y[($p + 1)] - $y[$p])/($x[($p + 1)] - $x[$p]);}
}

// Are there nodes? Check sign (+,0,-) for the 3 slope changes.

$sign[0] = ($m[1] - $m[0] == 0.0) ? ($sign[0] = 0) : (($m[1] - $m[0])/(abs($m[1] -


$m[0])));
$sign[1] = ($m[2] - $m[0] == 0.0) ? ($sign[1] = 0) : (($m[2] - $m[0])/(abs($m[2] -
$m[0])));
$sign[2] = ($m[3] - $m[1] == 0.0) ? ($sign[2] = 0) : (($m[3] - $m[1])/(abs($m[3] -
$m[1])));
$sign[3] = ($m[3] - $m[2] == 0.0) ? ($sign[3] = 0) : (($m[3] - $m[2])/(abs($m[3] -
$m[2])));

if (($sign[0] * $sign[1] >= 0) &&


($sign[2] * $sign[3] >= 0) &&
($sign[0] * $sign[3] <= 0))

{$node = true;
$inSmooth = ( $m[1] + ( ($m[1] - $m[0]) / 2.0 ) );
$outSmooth = ( $m[2] + ( ($m[2] - $m[3]) / 2.0 ) );}

else {$node = false;


$inSmooth = $m[1];
$outSmooth = $m[2];}

//as long as tangent is locked (handles move together), combine the two slope
values into one.
//Exception: if weights are free and also broken, treat angle as unified.

int $Weighted[] = `keyTangent -q -wt $curve`; $weighted = $Weighted[0];


if ($weighted == true)
{
float $oldIx[] = `keyTangent -in $i[2] -query -ix $curve`; $ix = ($oldIx[0] *
10.0);
float $oldOx[] = `keyTangent -in $i[2] -query -ox $curve`; $ox = ($oldOx[0] *
10.0);
}
int $Weightlock[] = `keyTangent -in $i[2] -q -weightLock $curve`; $weightlock =
$Weightlock[0];
int $Locked[] = `keyTangent -in $i[2] -q -lock $curve`; $locked = $Locked[0];
if (($locked == true) || ($weightlock == false))
{
$smooth = (($inSmooth + $outSmooth)/2.0);
$smooth = ($node == true) ? (shallower($smooth,(shallower(
( 2.0*$inSmooth),(2.0*$outSmooth))))) : ($smooth);
$inlimit = ( ( $smooth * $m[1] ) < 0 ) ? ( 0 ) : ( 3.0 * $m[1] );
$outlimit = ( ( $smooth * $m[2] ) < 0 ) ? ( 0 ) : ( 3.0 * $m[2] );
$limit = ( shallower( $inlimit, $outlimit ) );
$slope = ( shallower( $smooth, $limit ) );

//Correct overshoot for weighted curves.


if ($weighted == true)
{$slope = shallower($slope,(shallower((($y[2]-$y[1])/$ix),(($y[3]-$y[2])/$ox))));}
else {$slope = $slope;}

$inSlope = $slope;
$outSlope = $slope;
if ($locked == true)
{
keyTangent -in $i[2] -lock false $curve; // Temporarily unlock tangent.
}
}
else
{
$inlimit = ( ( $inSmooth * $m[1] ) < 0 ) ? ( 0 ) : ( 3 * $m[1] );
$outlimit = ( ( $outSmooth * $m[2] ) < 0 ) ? ( 0 ) : ( 3 * $m[2] );
$inSlope = ( shallower( $inSmooth, $inlimit ) );
$outSlope = ( shallower( $outSmooth, $outlimit ) );
}

$inAngle = atand ($inSlope);


$outAngle = atand ($outSlope);

// If curve is weighted, calculate weight for key.


if ($weighted == true)
{
$inweight = ( ( $x[2] - $x[1] ) / ( 3 * ( cosd ( $inAngle ) ) ) );
$outweight = ( ( $x[3] - $x[2] ) / ( 3 * ( cosd ( $outAngle ) ) ) );
// If it's the first key, set $inweight = $outweight. Reverse for last key.
if ($i[2] == 0) {$inweight = $outweight;}
if ($i[2] == $totalindexes - 1) {$outweight = $inweight;}
}
else
{
$inweight = 1;
$outweight = 1;
}

// Apply angle value to tangent of current key.


// If weights are free or nonweighted, leave weights alone.
if ((($weighted == true) && ($weightlock == false)) || ($weighted == false))
{
keyTangent -in $i[2] -ia $inAngle $curve;
keyTangent -in $i[2] -oa $outAngle $curve;
}
else
{
//...but for locked weighted keys, space weights evenly.
keyTangent -in $i[2] -ia $inAngle -iw $inweight $curve;
keyTangent -in $i[2] -oa $outAngle -ow $outweight $curve;
}

// Relock tangents.
if ($locked == true) {keyTangent -in $i[2] -lock true $curve;}

// end condition that tangency type must not be "step".


}
// Go to next key.
}
// Go to next curve.
}
waitCursor -state off; // put mouse cursor back to normal. -comet
// end procedure.
}
trdprty_tungsethTangent;
clear - Assign this to your ~ key. Cleans up all the crap you most likely don't
want on your screen

SelectAll;
setDisplaySmoothness 1;
select -cl ;

setObjectPickMask "Surface" false;

modelEditor -e -grid 0 modelPanel1;


modelEditor -e -grid 0 modelPanel2;
modelEditor -e -grid 0 modelPanel3;
modelEditor -e -grid 0 modelPanel4;

modelEditor -e -allObjects 0 modelPanel1;


modelEditor -e -allObjects 0 modelPanel2;
modelEditor -e -allObjects 0 modelPanel3;
modelEditor -e -allObjects 0 modelPanel4;

modelEditor -e -nurbsCurves 1 modelPanel1;


modelEditor -e -nurbsCurves 1 modelPanel2;
modelEditor -e -nurbsCurves 1 modelPanel3;
modelEditor -e -nurbsCurves 1 modelPanel4;

modelEditor -e -polymeshes 1 modelPanel1;


modelEditor -e -polymeshes 1 modelPanel2;
modelEditor -e -polymeshes 1 modelPanel3;
modelEditor -e -polymeshes 1 modelPanel4;

modelEditor -e -dimensions 1 modelPanel1;


modelEditor -e -dimensions 1 modelPanel2;
modelEditor -e -dimensions 1 modelPanel3;
modelEditor -e -dimensions 1 modelPanel4;

// sets pickers

setObjectPickMask "All" 0;
selectType -nurbsCurve 1;
selectType -locator 1;

/*

string $activePanel = `getPanel -wf`;


if (`modelEditor -q -nurbsCurves $activePanel` == 1) {
modelEditor -e -nurbsCurves 0 $activePanel;
} else {
modelEditor -e -nurbsCurves 1 $activePanel;
};
string $activePanel = `getPanel -wf`;
modelEditor -e -allObjects 0 $activePanel;
modelEditor -e -polymeshes 1 $activePanel;
modelEditor -e -nurbsSurfaces 1 $activePanel;
modelEditor -e -nurbsCurves 1 $activePanel;

*/;
// Error: file: C:/Program
Files/Autodesk/Maya2016/scripts/others/createModelPanelMenu.mel line 275: menuItem:
Object 'iselectEnableItem' not found. //
// sets pickers

setObjectPickMask "All" 0;
selectType -nurbsCurve 1;
selectType -locator 1;

/*

string $activePanel = `getPanel -wf`;


if (`modelEditor -q -nurbsCurves $activePanel` == 1) {
modelEditor -e -nurbsCurves 0 $activePanel;
} else {
modelEditor -e -nurbsCurves 1 $activePanel;
};

string $activePanel = `getPanel -wf`;


modelEditor -e -allObjects 0 $activePanel;
modelEditor -e -polymeshes 1 $activePanel;
modelEditor -e -nurbsSurfaces 1 $activePanel;
modelEditor -e -nurbsCurves 1 $activePanel;

*/;

You might also like