// smartTransform.mel // Script to interpolate transform value in the order of selection // Author: Volker Heisterberg (volk@renderwahnsinn.de) // Usage: Select many objects to interpolate values from first to last selection // Version History: // 1.0: First Release as smartTransform.mel global proc smartTransform() { if ((`window -ex smartWindow`) == 1) deleteUI -window smartWindow; window -title "SmartTransform 1.0" -menuBar true -widthHeight 700 290 smartyWindow; // globale Variablen definieren global int $oldTX_check=0; global int $oldTY_check=0; global int $oldTZ_check=0; global int $oldRX_check=0; global int $oldRY_check=0; global int $oldRZ_check=0; global int $oldSX_check=0; global int $oldSY_check=0; global int $oldSZ_check=0; global float $oldTX_from=0; global float $oldTY_from=0; global float $oldTZ_from=0; global float $oldRX_from=0; global float $oldRY_from=0; global float $oldRZ_from=0; global float $oldSX_from=0; global float $oldSY_from=0; global float $oldSZ_from=0; global float $oldTX_to=0; global float $oldTY_to=0; global float $oldTZ_to=0; global float $oldSX_to=0; global float $oldSY_to=0; global float $oldSZ_to=0; global float $oldRX_to=0; global float $oldRY_to=0; global float $oldRZ_to=0; //command string $command = "int $testTx=`checkBox -q -v txCheck`; if ($testTx>0) { $oldTX_from = `floatField -q -v tx_from_field`; $oldTX_to = `floatField -q -v tx_to_field`; smartInt(1, $oldTX_from, $oldTX_to);}"; $command += "int $testTy=`checkBox -q -v tyCheck`; if ($testTy>0) { $oldTY_from = `floatField -q -v ty_from_field`; $oldTY_to = `floatField -q -v ty_to_field`; smartInt(2, $oldTY_from, $oldTY_to);}"; $command += "int $testTz=`checkBox -q -v tzCheck`; if ($testTz>0) { $oldTZ_from = `floatField -q -v tz_from_field`; $oldTZ_to = `floatField -q -v tz_to_field`; smartInt(3, $oldTZ_from, $oldTZ_to);}"; $command += "int $testRx=`checkBox -q -v rxCheck`; if ($testRx>0) { $oldRX_from = `floatField -q -v rx_from_field`; $oldRX_to = `floatField -q -v rx_to_field`; smartInt(4, $oldRX_from, $oldRX_to);}"; $command += "int $testRy=`checkBox -q -v ryCheck`; if ($testRy>0) { $oldRY_from = `floatField -q -v ry_from_field`; $oldRY_to = `floatField -q -v ry_to_field`; smartInt(5, $oldRY_from, $oldRY_to);}"; $command += "int $testRz=`checkBox -q -v rzCheck`; if ($testRz>0) { $oldRZ_from = `floatField -q -v rz_from_field`; $oldRZ_to = `floatField -q -v rz_to_field`; smartInt(6, $oldRZ_from, $oldRZ_to);}"; $command += "int $testSx=`checkBox -q -v sxCheck`; if ($testSx>0) { $oldSX_from = `floatField -q -v sx_from_field`; $oldSX_to = `floatField -q -v sx_to_field`; smartInt(7, $oldSX_from, $oldSX_to);}"; $command += "int $testSy=`checkBox -q -v syCheck`; if ($testSy>0) { $oldSY_from = `floatField -q -v sy_from_field`; $oldSY_to = `floatField -q -v sy_to_field`; smartInt(8, $oldSY_from, $oldSY_to);}"; $command += "int $testSz=`checkBox -q -v szCheck`; if ($testSz>0) { $oldSZ_from = `floatField -q -v sz_from_field`; $oldSZ_to = `floatField -q -v sz_to_field`; smartInt(9, $oldSZ_from, $oldSZ_to);}"; // Layout definieren columnLayout; rowColumnLayout -numberOfRows 9; checkBox -label "Interpolate TranslateX from " -onc "button -e -en 1 switchTX;floatField -e -en 1 tx_from_field; floatField -e -en 1 tx_to_field; $oldTX_check=1;" -ofc "button -e -en 0 switchTX;floatField -e -en 0 tx_from_field; floatField -e -en 0 tx_to_field; $oldTX_check=0;" -v $oldTX_check txCheck; checkBox -label "Interpolate TranslateY from " -onc "button -e -en 1 switchTY;floatField -e -en 1 ty_from_field; floatField -e -en 1 ty_to_field; $oldTY_check=1;" -ofc "button -e -en 0 switchTY;floatField -e -en 0 ty_from_field; floatField -e -en 0 ty_to_field; $oldTY_check=0;" -v $oldTY_check tyCheck; checkBox -label "Interpolate TranslateZ from " -onc "button -e -en 1 switchTZ;floatField -e -en 1 tz_from_field; floatField -e -en 1 tz_to_field; $oldTZ_check=1;" -ofc "button -e -en 0 switchTZ;floatField -e -en 0 tz_from_field; floatField -e -en 0 tz_to_field; $oldTZ_check=0;" -v $oldTZ_check tzCheck; checkBox -label "Interpolate RotateX from " -onc "button -e -en 1 switchRX;floatField -e -en 1 rx_from_field; floatField -e -en 1 rx_to_field; $oldRX_check=1;" -ofc "button -e -en 0 switchRX;floatField -e -en 0 rx_from_field; floatField -e -en 0 rx_to_field; $oldRX_check=0;" -v $oldRX_check rxCheck; checkBox -label "Interpolate RotateY from " -onc "button -e -en 1 switchRY;floatField -e -en 1 ry_from_field; floatField -e -en 1 ry_to_field; $oldRY_check=1;" -ofc "button -e -en 0 switchRY;floatField -e -en 0 ry_from_field; floatField -e -en 0 ry_to_field; $oldRY_check=0;" -v $oldRY_check ryCheck; checkBox -label "Interpolate RotateZ from " -onc "button -e -en 1 switchRZ;floatField -e -en 1 rz_from_field; floatField -e -en 1 rz_to_field; $oldRZ_check=1;" -ofc "button -e -en 0 switchRZ;floatField -e -en 0 rz_from_field; floatField -e -en 0 rz_to_field; $oldRZ_check=0;" -v $oldRZ_check rzCheck; checkBox -label "Interpolate ScaleX from " -onc "button -e -en 1 switchSX;floatField -e -en 1 sx_from_field; floatField -e -en 1 sx_to_field; $oldSX_check=1;" -ofc "button -e -en 0 switchSX;floatField -e -en 0 sx_from_field; floatField -e -en 0 sx_to_field; $oldSX_check=0;" -v $oldSX_check sxCheck; checkBox -label "Interpolate ScaleY from " -onc "button -e -en 1 switchSY;floatField -e -en 1 sy_from_field; floatField -e -en 1 sy_to_field; $oldSY_check=1;" -ofc "button -e -en 0 switchSY;floatField -e -en 0 sy_from_field; floatField -e -en 0 sy_to_field; $oldSY_check=0;" -v $oldSY_check syCheck; checkBox -label "Interpolate ScaleZ from " -onc "button -e -en 1 switchSZ;floatField -e -en 1 sz_from_field; floatField -e -en 1 sz_to_field; $oldSZ_check=1;" -ofc "button -e -en 1 switchSZ;floatField -e -en 0 sz_from_field; floatField -e -en 0 sz_to_field; $oldSZ_check=0;" -v $oldSZ_check szCheck; floatField -value ($oldTX_from) -s 1 -en ($oldTX_check) tx_from_field; floatField -value ($oldTY_from) -s 1 -en ($oldTY_check) ty_from_field; floatField -value ($oldTZ_from) -s 1 -en ($oldTZ_check) tz_from_field; floatField -value ($oldRX_from) -s 1 -en ($oldRX_check) rx_from_field; floatField -value ($oldRY_from) -s 1 -en ($oldRY_check) ry_from_field; floatField -value ($oldRZ_from) -s 1 -en ($oldRZ_check) rz_from_field; floatField -value ($oldSX_from) -s 1 -en ($oldSX_check) sx_from_field; floatField -value ($oldSY_from) -s 1 -en ($oldSY_check) sy_from_field; floatField -value ($oldSZ_from) -s 1 -en ($oldSZ_check) sz_from_field; text -label " to "; text -label " to "; text -label " to "; text -label " to "; text -label " to "; text -label " to "; text -label " to "; text -label " to "; text -label " to "; floatField -value ($oldTX_to) -s 1 -en ($oldTX_check) tx_to_field; floatField -value ($oldTY_to) -s 1 -en ($oldTY_check) ty_to_field; floatField -value ($oldTZ_to) -s 1 -en ($oldTZ_check) tz_to_field; floatField -value ($oldRX_to) -s 1 -en ($oldRX_check) rx_to_field; floatField -value ($oldRY_to) -s 1 -en ($oldRY_check) ry_to_field; floatField -value ($oldRZ_to) -s 1 -en ($oldRZ_check) rz_to_field; floatField -value ($oldSX_to) -s 1 -en ($oldSX_check) sx_to_field; floatField -value ($oldSY_to) -s 1 -en ($oldSY_check) sy_to_field; floatField -value ($oldSZ_to) -s 1 -en ($oldSZ_check) sz_to_field; button -label "Switch" -c "float $a = `floatField -q -v tx_from_field`; floatField -e -v (`floatField -q -v tx_to_field`) tx_from_field; floatField -e -v ($a) tx_to_field; $oldTX_to = $a; $oldTX_from = (`floatField -q -v tx_from_field`);" -en ($oldTX_check) switchTX; button -label "Switch" -c "float $a = `floatField -q -v ty_from_field`; floatField -e -v (`floatField -q -v ty_to_field`) ty_from_field; floatField -e -v ($a) ty_to_field; $oldTY_to = $a; $oldTY_from = (`floatField -q -v ty_from_field`);" -en ($oldTY_check) switchTY; button -label "Switch" -c "float $a = `floatField -q -v tz_from_field`; floatField -e -v (`floatField -q -v tz_to_field`) tz_from_field; floatField -e -v ($a) tz_to_field; $oldTZ_to = $a; $oldTZ_from = (`floatField -q -v tz_from_field`);" -en ($oldTZ_check) switchTZ; button -label "Switch" -c "float $a = `floatField -q -v rx_from_field`; floatField -e -v (`floatField -q -v rx_to_field`) rx_from_field; floatField -e -v ($a) rx_to_field; $oldRX_to = $a; $oldRX_from = (`floatField -q -v rx_from_field`);" -en ($oldRX_check) switchRX; button -label "Switch" -c "float $a = `floatField -q -v ry_from_field`; floatField -e -v (`floatField -q -v ry_to_field`) ry_from_field; floatField -e -v ($a) ry_to_field; $oldRY_to = $a; $oldRY_from = (`floatField -q -v ry_from_field`);" -en ($oldRY_check) switchRY; button -label "Switch" -c "float $a = `floatField -q -v rz_from_field`; floatField -e -v (`floatField -q -v rz_to_field`) rz_from_field; floatField -e -v ($a) rz_to_field; $oldRZ_to = $a; $oldRZ_from = (`floatField -q -v rz_from_field`);" -en ($oldRZ_check) switchRZ; button -label "Switch" -c "float $a = `floatField -q -v sx_from_field`; floatField -e -v (`floatField -q -v sx_to_field`) sx_from_field; floatField -e -v ($a) sx_to_field; $oldSX_to = $a; $oldSX_from = (`floatField -q -v sx_from_field`);" -en ($oldSX_check) switchSX; button -label "Switch" -c "float $a = `floatField -q -v sy_from_field`; floatField -e -v (`floatField -q -v sy_to_field`) sy_from_field; floatField -e -v ($a) sy_to_field; $oldSY_to = $a; $oldSY_from = (`floatField -q -v sy_from_field`);" -en ($oldSY_check) switchSY; button -label "Switch" -c "float $a = `floatField -q -v sz_from_field`; floatField -e -v (`floatField -q -v sz_to_field`) sz_from_field; floatField -e -v ($a) sz_to_field; $oldSZ_to = $a; $oldSZ_from = (`floatField -q -v sz_from_field`);" -en ($oldSX_check) switchSZ; button -label "Update From Value" -c "string $selection[] = `ls -sl`; float $fromTx = `getAttr ($selection[0] + \".tx\")`; floatField -e -value $fromTx tx_from_field;"; button -label "Update From Value" -c "string $selection[] = `ls -sl`; float $fromTy = `getAttr ($selection[0] + \".ty\")`; floatField -e -value $fromTy ty_from_field;"; button -label "Update From Value" -c "string $selection[] = `ls -sl`; float $fromTz = `getAttr ($selection[0] + \".tz\")`; floatField -e -value $fromTz tz_from_field;"; button -label "Update From Value" -c "string $selection[] = `ls -sl`; float $fromRx = `getAttr ($selection[0] + \".rx\")`; floatField -e -value $fromRx rx_from_field;"; button -label "Update From Value" -c "string $selection[] = `ls -sl`; float $fromRy = `getAttr ($selection[0] + \".ry\")`; floatField -e -value $fromRy ry_from_field;"; button -label "Update From Value" -c "string $selection[] = `ls -sl`; float $fromRz = `getAttr ($selection[0] + \".rz\")`; floatField -e -value $fromRz rz_from_field;"; button -label "Update From Value" -c "string $selection[] = `ls -sl`; float $fromSx = `getAttr ($selection[0] + \".sx\")`; floatField -e -value $fromSx sx_from_field;"; button -label "Update From Value" -c "string $selection[] = `ls -sl`; float $fromSy = `getAttr ($selection[0] + \".sy\")`; floatField -e -value $fromSy sy_from_field;"; button -label "Update From Value" -c "string $selection[] = `ls -sl`; float $fromSz = `getAttr ($selection[0] + \".sz\")`; floatField -e -value $fromSz sz_from_field;"; button -label "Update To Value" -c "string $selection[] = `ls -sl`; float $fromTx = `getAttr ($selection[0] + \".tx\")`; floatField -e -value $fromTx tx_to_field;"; button -label "Update To Value" -c "string $selection[] = `ls -sl`; float $fromTy = `getAttr ($selection[0] + \".ty\")`; floatField -e -value $fromTy ty_to_field;"; button -label "Update To Value" -c "string $selection[] = `ls -sl`; float $fromTz = `getAttr ($selection[0] + \".tz\")`; floatField -e -value $fromTz tz_to_field;"; button -label "Update To Value" -c "string $selection[] = `ls -sl`; float $fromRx = `getAttr ($selection[0] + \".rx\")`; floatField -e -value $fromRx rx_to_field;"; button -label "Update To Value" -c "string $selection[] = `ls -sl`; float $fromRy = `getAttr ($selection[0] + \".ry\")`; floatField -e -value $fromRy ry_to_field;"; button -label "Update To Value" -c "string $selection[] = `ls -sl`; float $fromRz = `getAttr ($selection[0] + \".rz\")`; floatField -e -value $fromRz rz_to_field;"; button -label "Update To Value" -c "string $selection[] = `ls -sl`; float $fromSx = `getAttr ($selection[0] + \".sx\")`; floatField -e -value $fromSx sx_to_field;"; button -label "Update To Value" -c "string $selection[] = `ls -sl`; float $fromSy = `getAttr ($selection[0] + \".sy\")`; floatField -e -value $fromSy sy_to_field;"; button -label "Update To Value" -c "string $selection[] = `ls -sl`; float $fromSz = `getAttr ($selection[0] + \".sz\")`; floatField -e -value $fromSz sz_to_field;"; setParent ..; rowColumnLayout -numberOfRows 1; button -label "Apply" -width 265 -c $command; button -label "Cancel" -width 265 -c "deleteUI -window smartyWindow"; showWindow smartyWindow; } global proc smartInt(int $attr, float $from, float $to) { print ("Received Attribute " + $attr + " from " + $from + " to " + $to + "\n"); string $selectionList[] = `ls -sl`; int $count = size($selectionList); if ($count<2) error "Not enough objects selected!"; float $step = (($to)-($from))/($count-1); print ("Step is " + $step + " and count is " + $count + "!\n"); switch ($attr) { case 1: for ($i=0; $i<$count; $i++) { print ("set Attr TX\n"); setAttr ($selectionList[$i] + ".translateX") ($from+$i*$step); } break; case 2: for ($i=0; $i<$count; $i++) { print ("set Attr TY\n"); setAttr ($selectionList[$i] + ".translateY") ($from+$i*$step); } break; case 3: for ($i=0; $i<$count; $i++) { print ("set Attr TZ\n"); setAttr ($selectionList[$i] + ".translateZ") ($from+$i*$step); } break; case 4: for ($i=0; $i<$count; $i++) { print ("set Attr\n"); setAttr ($selectionList[$i] + ".rotateX") ($from+$i*$step); } break; case 5: for ($i=0; $i<$count; $i++) { print ("set Attr\n"); setAttr ($selectionList[$i] + ".rotateY") ($from+$i*$step); } break; case 6: for ($i=0; $i<$count; $i++) { print ("set Attr\n"); setAttr ($selectionList[$i] + ".rotateZ") ($from+$i*$step); } break; case 7: for ($i=0; $i<$count; $i++) { print ("set Attr\n"); setAttr ($selectionList[$i] + ".scaleX") ($from+$i*$step); } break; case 8: for ($i=0; $i<$count; $i++) { print ("set Attr\n"); setAttr ($selectionList[$i] + ".scaleY") ($from+$i*$step); } break; case 9: for ($i=0; $i<$count; $i++) { print ("set Attr SZ\n"); setAttr ($selectionList[$i] + ".scaleZ") ($from+$i*$step); } break; default: break; } }