scrub keyframe script availible... :-)


#1

Hi,

a couple of years ago someone requested a scrub keyframe script… as I recall it was on Jason Schleifers forum…
however that forum has changed and I can’t find the post…
however I found the script I worked on back then… and fixed and updated it…

so here you go… a scrub keyframe script… :slight_smile:

regards

Strarup


//scrubKeys...
/*
''   Script Name:   Scrub da keys v0.2
''   Author:		Alex V. U. Strarup
''   E-mail:		[email="http://forums.cgsociety.org/3d@strarup.net"]3d@strarup.net[/email]
''   Web-site:	  [http://www.strarup.net](http://www.strarup.net)
''   Created:	   21. may. 2004
''   Last Updated:   5. nov. 2007
''
*/

////////////////////////////////////////////////////////////////////////////////////////////
//
//  DESCRIPTION : script to scrub thru keyframes for the selected object...
//
////////////////////////////////////////////////////////////////////////////////////////////
//
//  put the script in the script folder :-)
//
////////////////////////////////////////////////////////////////////////////////////////////
//
//  How to call the script, just write...
//  daScrubKeysHelperUI; in the commandline
//
////////////////////////////////////////////////////////////////////////////////////////////
//
//  Conditions : Use at your own risk, No Banana throwing or whatever if it doesn't work...
//
////////////////////////////////////////////////////////////////////////////////////////////

proc daScrubKeysHelperUI()
{
	 if (`window -exists daScrubKeysHelperWindowUI`)
		  deleteUI daScrubKeysHelperWindowUI;

	 window -wh 310 400 -rtf true -title "Scrub between da keys..." daScrubKeysHelperWindowUI;
	 formLayout daScrubKeysHelperWindowUIFormLayout;
	 text -fn "boldLabelFont" -w 300 -label "The Selected Object..." daSKHWLabel1;
	 //textfield with the selected obj... if any is selected... or the first object from a selection...
	 textField -w 300 -ed false -ann "this field is used to hold the name of the selected Object..." daSKHWTxtFld;
	 separator -w 310 -h 3 -style "out" "daSKHWSep01" ;
	 //label field if no keys on object
	 text -fn "boldLabelFont" -al "center" -w 300 -label "No Keyframes on seleted object..." daSKHWLabel2;
	 //scrub key slider
	 intSlider -vis 0 -w 300 -s 1 -min 0 -max 100 -dc "doDaScrub(0);" -cc "doDaScrub(0);" -ann "slider for scrubing da keys for the selected object..." daSKHWiSlider;
	 separator -w 310 -h 3 -style "out" "daSKHWSep02" ;
	 //prev key button
	 symbolButton -image "timeprev.xpm" -en false -w 50 -ann "go to previous key" -c "doDaScrub(1);" daSKHWpreBtn;
	 //next key button...
	 symbolButton -image "timenext.xpm" -en false -w 50 -ann "go to next key" -c "doDaScrub(2);" daSKHWnexBtn;
	 separator -w 310 -h 3 -style "out" "daSKHWSep03" ;
	 //button update
	 button -al "center" -label "Update UI" -en 1 -w 100 -ann "updating the UI..." -c "doDaUpdateScrubKeysHelperUI;" daSKHWupdBtn;


	 formLayout -e
		 -af "daSKHWLabel1" "left" 10
		 -af "daSKHWLabel1"  "top" 15
		 -af "daSKHWTxtFld" "left" 10
		 -af "daSKHWTxtFld"  "top" 40
		 -af "daSKHWSep01" "left" 5
		 -af "daSKHWSep01" "top" 65
		 -af "daSKHWLabel2" "left" 10
		 -af "daSKHWLabel2" "top" 80
		 -af "daSKHWiSlider" "left" 10
		 -af "daSKHWiSlider" "top" 80
		 -af "daSKHWSep02" "left" 5
		 -af "daSKHWSep02" "top" 110
		 -af "daSKHWpreBtn" "left" 95
		 -af "daSKHWpreBtn" "top" 125
		 -af "daSKHWnexBtn" "left" 155
		 -af "daSKHWnexBtn" "top" 125
		 -af "daSKHWSep03" "left" 5
		 -af "daSKHWSep03" "top" 160
		 -af "daSKHWupdBtn" "left" 100
		 -af "daSKHWupdBtn" "top" 175
	 daScrubKeysHelperWindowUIFormLayout;
	 doDaUpdateScrubKeysHelperUI;
	 showWindow daScrubKeysHelperWindowUI;
}
daScrubKeysHelperUI;

proc doDaUpdateScrubKeysHelperUI()
{
	string $daSelObj[] = `ls -sl -l`;
	float $daScrub[];
	float $daCTime = `currentTime -q`;
	int $daMSV;// = size($daScrub);
	int $daStep;
	float $daClosestTime;
	if(size($daSelObj)!=0)
	{
	   textField -e -tx $daSelObj[0] daSKHWTxtFld;
	   $daScrub =  daScrubKeys($daSelObj[0]);
	   $daMSV =size($daScrub);
	   if($daMSV==0)
	   {
		  text -e -vis 1 -label "No Keyframes on selected object..." daSKHWLabel2;
		  intSlider -e -vis 0 daSKHWiSlider;
		  symbolButton -e -en 0 daSKHWpreBtn;
		  symbolButton -e -en 0 daSKHWnexBtn;
	   }
	   else if($daMSV>0)
	   {
		  $daClosestTime =  doDaGetDaClosestTime($daScrub,$daCTime);
		  intSlider -e -vis 1 -s 1 -min 0 -max $daMSV -v $daClosestTime daSKHWiSlider;
		  text -e -vis 0 daSKHWLabel2;
		  symbolButton -e -en 1 daSKHWpreBtn;
		  symbolButton -e -en 1 daSKHWnexBtn;
		  doDaScrub(0);
	   }
	}
	else
	{
	   textField -e -tx "Nothing Selected" daSKHWTxtFld;
	   text -e -vis 1 -label "No Keyframes No Object Selected..." daSKHWLabel2;
	   //text -e -vis 1 -al "center" -label "No Woman... No Cry... ;-)" daSKHWLabel2;
	   intSlider -e -vis 0 daSKHWiSlider;	   
	   symbolButton -e -en 0 daSKHWpreBtn;
	   symbolButton -e -en 0 daSKHWnexBtn;
	}
}

proc int doDaGetDaClosestTime(float $daArr[], float $daTime)
{
   float $daClosestTime;
   float $daMiV, $daMav;
   for($i=0; $i<size($daArr);$i++)
   {
	  if($daTime  == $daArr[$i])
	  {
		 $daClosestTime = $i;
		 break;
	  }
	  if(($daTime > $daArr[$i])&& ($daTime < $daArr[($i+1)]))
	  {
		  $daMiV = $daTime - $daArr[$i];
		  $daMav = $daArr[($i+1)] - $daTime;
		  if($daMiV >= $daMav)
		  {
			$daClosestTime = $i+1;
		  }
		  else{$daClosestTime = $i;}
		  break;
	  }
	  if($daTime > $daArr[$i]){$daClosestTime = $i;}

   }
   return $daClosestTime;
}

proc doDaScrub(int $daCmd)
{
	 string $daObj = `textField -q -tx daSKHWTxtFld`;
	 float $daScrub[] =  daScrubKeys($daObj);
	 int $daNr =  `intSlider -q -v daSKHWiSlider`;
	 int $daMin = `intSlider -q -min daSKHWiSlider`;
	 int $daMax = `intSlider -q -max daSKHWiSlider`;
	 //scrubing the slider
	 if($daCmd == 0)
	 {
		currentTime -edit $daScrub[$daNr];
	 }
	 //get da previous key...
	 if($daCmd == 1)
	 {
		if($daNr != $daMin)
		{
		   intSlider -e -v ($daNr-1) daSKHWiSlider;
		   currentTime -edit $daScrub[($daNr-1)];
		}
	 }
	 //get da next key...
	 if($daCmd == 2)
	 {
		if($daNr != $daMax)
		{
		   intSlider -e -v ($daNr+1) daSKHWiSlider;
		   currentTime -edit $daScrub[($daNr+1)];
		}
	 }
}

proc float[] daScrubKeys(string $daObj)
{
		float $flKeyList[], $flSoKeyList[];
		string $stKeylist[], $stRD_KeyList[];
 int $j = 0;
		//get all the keyframes for the selected object...
 $flKeyList = `keyframe -q -timeChange $daObj`;
 //and sort them...
 $flSoKeyList = sort($flKeyList);
 //append the keyframe float value to a string
 for($j=0; $j<size($flKeyList); $j++)
 {
  $stKeylist[$j] = (""+$flSoKeyList[$j]);
 }
 //remove redundant keyframes from the list
 $stRD_KeyList = stringArrayRemoveDuplicates($stKeylist);
		clear $flKeyList;
		for($i = 0; $i < size($stRD_KeyList); $i++)
 {$flKeyList[$i]= float($stRD_KeyList[$i]);}
 return $flKeyList;
}


#2

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.