Thought I’d come and share some of the scripts that I’ve written that have made the long-term cut.
To be sourced and run via SGT_SGTweakWindow(). See video at creativecrash here.
/*
Object Tweaker v 0.3 by Steven E. Geer
* Selected objects are given random rotation, translation, or scale values in X, Y or Z.
* Modify at own risk.
* Contact: stevenegeer (at) gmail
*/
global proc SGT_executeTweak(){
string $checkedAxes[];
string $checkedDir[];
string $empty[] = {""};
string $flagged[];
$checkedAxes[0] = (`checkBoxGrp -query -value1 axesCheckGroup`) == 1 ? "X" : "";
$checkedAxes[1] = (`checkBoxGrp -query -value2 axesCheckGroup`) == 1 ? "Y" : "";
$checkedAxes[2] = (`checkBoxGrp -query -value3 axesCheckGroup`) == 1 ? "Z" : "";
$checkedDir[0] = (`checkBoxGrp -query -value1 dirCheckGroup`) == 1 ? "-ro" : "";
$checkedDir[1] = (`checkBoxGrp -query -value2 dirCheckGroup`) == 1 ? "-t" : "";
$checkedDir[2] = (`checkBoxGrp -query -value3 dirCheckGroup`) == 1 ? "-s" : "";
string $finalCtxArray[] = stringArrayRemove($empty, $checkedAxes);
string $finalDirArray[] = stringArrayRemove($empty, $checkedDir);
float $finalAmount = `floatSliderGrp -query -value amountSliderGroup`;
float $multiplier = `floatSliderGrp -query -value multiplierGroup`;
$flagged[0] = (`radioButtonGrp -q -select translatePositioning` == 1) ? "-r" : "-a";
$flagged[1] = (`radioButtonGrp -q -select rotatePositioning` == 1) ? "-r" : "-a";
$flagged[2] = (`radioButtonGrp -query -select spaceRadioGroup`) == 1 ? "-ws" : "-os";
if((size($finalCtxArray) && size($finalDirArray)) != 0){
SGT_tweak($checkedAxes, $finalAmount*$multiplier, $checkedDir, $flagged);
}else{
error("You must have at least one axis and one context selected.");
}
}
global proc SGT_tweak(string $direction[], float $maxAmount, string $ctx[], string $flags[]){
float $amount;
int $i = 0;
int $curObject = 0;
string $sel[] = `ls -sl`;
string $attr;
if(size($sel) == 0){
error("You must have at least one object selected.");
}else{
string $rValues[];
string $tValues[];
string $sValues[];
int $isRot = 0;
int $isTrans = 0;
int $isScale = 0;
int $pAmount = 0;
progressWindow
-title "Tweaking..."
-progress $pAmount
-status "Tweaking Objects "
-isInterruptable true
-min 0
-max `size $sel`;
for($object in $sel){
float $startScale[] = `xform -r -q -s $object`;
float $delta;
if(`progressWindow -q -ic`) break;
$curObject++;
progressWindow -edit -status ($curObject+"/"+size($sel));
progressWindow -edit -progress $curObject;
for($cx in $ctx){
if($cx != ""){
switch($cx){
case "-ro":
$delta = rand($maxAmount * -1, $maxAmount);
for($i = 0; $i < 3; $i++){
$rValues[$i] = ($direction[$i] == "" ? "0" : $delta + " ");
}
$isRot = 1;
break;
case "-s":
$delta = rand( ($maxAmount*.1)*-1, $maxAmount*.1);
for($i = 0; $i < 3; $i++){
$sValues[$i] = ($direction[$i] == "" ? "0" : $startScale[$i] + ($delta) + " ");
}
$isScale = 1;
break;
case "-t":
float $delta = rand( ($maxAmount/2)*-1, $maxAmount/2 );
for($i = 0; $i < 3; $i++){
$tValues[$i] = ($direction[$i] == "" ? "0" : $delta + " ");
}
$isTrans = 1;
break;
}
}
}
//perform each move seperate
if($isRot == 1){
string $rn = stringArrayToString($rValues, " ");
string $tok[];
tokenizeList($rn, $tok);
string $command = ("xform "+$flags[2]+" "+ $flags[1] +" -ro ");
for($bar in $tok){
$command += ($bar + " ");
}
$command += ($object);
eval($command);
}
if($isTrans == 1){
string $tn = stringArrayToString($tValues, " ");
string $tok[];
tokenizeList($tn, $tok);
string $command = ("xform "+$flags[0]+" " + $flags[0] + " -t ");
for($bar in $tok){
$command += ($bar + " ");
}
$command += ($object);
eval($command);
}
if($isScale == 1){
string $sn = stringArrayToString($sValues, " ");
string $tok[];
tokenizeList($sn, $tok);
string $command = ("xform "+$flags[2]+" -s ");
for($bar in $tok){
$command += ($bar + " ");
}
$command += ($object);
eval($command);
}
clear $startScale;
if($curObject == size($sel)) progressWindow -endProgress;
}
}
}
global proc SGT_SGTweakWindow(){
if(`window -exists SGTweakerWindow`) deleteUI SGTweakerWindow;
if(`windowPref -exists SGTweakerWindow`) windowPref -remove SGTweakerWindow;
string $axes[] = {"X", "Y", "Z"};
string $context[] = {"r", "t", "s"};
float $amount;
string $tweakWindow =
`window -t "Tweak v 0.3" -s 0 -wh 400 230 -mnb true SGTweakerWindow`;
columnLayout -adj 1 columnContainer;
separator -h 10;
setParent columnContainer;
rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5;
text -l "Axes" -w 100;
rowLayout -nc 1 -cw1 100;
checkBoxGrp -ncb 3 -la3 "X" "Y" "Z" -va3 true true true -cw3 70 70 70 axesCheckGroup;
setParent columnContainer;
rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5;
text -l "Context" -w 100;
rowLayout -nc 1 -cw1 100;
checkBoxGrp -ncb 3 -la3 "Rotate" "Translate" "Scale" -va3 true false false -cw3 70 70 70 dirCheckGroup;
setParent columnContainer;
rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5;
text -l "Tweak Amount" -w 100;
rowLayout -nc 1 -cw1 100;
floatSliderGrp -f true -min 0.0001 -max 5 -fmx 5 -fmn 0.0001 -pre 4 -v 1 amountSliderGroup;
setParent columnContainer;
rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5 multCol;
text -l "Multiplier" -w 100;
rowLayout -nc 1 -cw1 100 multiCol1;
floatSliderGrp -f true -min .1 -max 5 -fmx 5 -v 1 -pre 1 multiplierGroup;
setParent columnContainer;
separator -height 20;
setParent columnContainer;
columnLayout -adj true -p columnContainer;
frameLayout -l "Flags" -cll 1 -pcc "int $winHeight = `window -q -h SGTweakerWindow`; window -e -h ($winHeight - 120) SGTweakerWindow;" -pec "int $winHeight = `window -q -h SGTweakerWindow`; window -e -h ($winHeight + 120) SGTweakerWindow;" -cl 1
flagGroup;
columnLayout -adj 1
localCol;
rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 2 "top" 5;
text -l "Space" -w 100;
rowLayout -nc 1 -cw1 100;
radioButtonGrp -nrb 2 -sl 1 -la2 "World" "Object" spaceRadioGroup;
setParent localCol;
separator -h 20 -vis 1;
setParent localCol;
frameLayout -l "Context Positioning" -cll 0 -mh 10 -mw 0 -li 150 -bs "etchedOut" -h 80
positionGroup;
columnLayout posLocal;
rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 1 "top" 5 -rat 2 "top" 5;
text -l "Translate" -w 100;
rowLayout -nc 1 -cw1 100;
radioButtonGrp -nrb 2 -sl 1 -la2 "Relative" "Absolute" translatePositioning;
setParent posLocal;
rowLayout -nc 2 -cw2 130 120 -cl2 "right" "left" -rat 2 "top" 4;
text -l "Rotate" -w 100;
rowLayout -nc 2 -cw1 100;
radioButtonGrp -nrb 2 -sl 1 -la2 "Relative" "Absolute" rotatePositioning;
setParent localCol;
setParent columnContainer;
separator -h 20;
rowColumnLayout -nc 2 -cw 1 175 -cw 2 175 -cal 1 "center" -cal 1 "center" -co 1 "left" 40 -co 2 "left" 40 -w 400 bottomCol;
button -w 200 -l "Apply" -c "SGT_executeTweak";
button -w 200 -l "Close" -c "deleteUI SGTweakerWindow";
showWindow $tweakWindow;
}
Simple snap A to B
global proc snapObject(){
string $sel[] = `ls -sl`;
if(size($sel) != 2){
error("You must have only 2 objects selected.");
}else{
string $parent = $sel[1];
string $child = $sel[0];
float $parentCoord[] = `xform -q -ws -t $parent`;
xform -ws -t $parentCoord[0] $parentCoord[1] $parentCoord[2] $child;
}
}
snapObject();
And a script to attach a bokeh node to a camera based on a selected object (Select Object, then Camera and run)
global proc bokeh(){
string $sel[] = `ls -sl`;
float $childPos[] = `xform -q -t $sel[0]`;
float $camPos[] = `xform -q -t $sel[1]`;
string $cShape[] = `listRelatives -s $sel[1]`;
string $cameraNode = $sel[1];
setAttr ($cameraNode + ".scaleX") 1;
setAttr ($cameraNode + ".scaleY") 1;
setAttr ($cameraNode + ".scaleZ") 1;
float $scaleX = `getAttr ($sel[1]+".scaleX")`;
string $bokehNode = ($sel[1]+"_bokeh");
string $ddShape = ($cShape[0]+"_ddm");
string $dd = `distanceDimension -sp $childPos[0] $childPos[1] $childPos[2] -ep $camPos[0] $camPos[1] $camPos[2]`;
rename $dd $ddShape;
string $con[] = `listConnections $ddShape`;
parent $con[1] $sel[1];
string $bokeh = `mrCreateCustomNode -asUtility "" mia_lens_bokeh`;
rename $bokeh $bokehNode;
float $distance = `getAttr ($ddShape+".distance")`;
float $correctedDistance = $distance / $scaleX;
connectAttr -f ($bokehNode+".message") ($cShape[0]+".miLensShader");
setAttr ($bokehNode+".plane") $correctedDistance;
}
bokeh();