You can do this via 2 ways each has its implications.
- Via scriptJob (it is executed when you release the mouse after changing the current frame, so it does not work while dragging):
//define a proc to run and put the code you want to excute inside
global proc printTime()
{
print ("frame: " + currentTime -q
+ "\n");
}
//create the scriptJob, it is triggered when the time changes
int $jobNum = scriptJob -e "timeChanged" "printTime"
;
//delete scriptJob
scriptJob -kill $jobNum -force;
- Via expresion ( it is executed each frame, works while dragging and changing frame in the timeslider):
Create the expresion and put the code you want inside (expression syntax is a little different than pure MEL, search documentation)
ex (run the following code to create an expression):
expression -e -s "print (\"frame: \" + currentTime -q
+ \"\n\");" -o "" -ae 1 -uc all printTime_exp;
It is advised not to run getAttr/setAttr commands inside expressions for performance reasons though it is possible.