--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CADHeb2Z8NXCQVc79PODDY80qj6Szp27NN%2BhZ_8%3Dt0SYiv1xBLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAaAJ6G1teCW%3D8gbMnrmEUqE25zPGfG_ZWbRV%2B2muHdNA%40mail.gmail.com.
Here is one way of doing it.
import time
from maya import OpenMaya as om
time.__previous = time.time()
def callback(*args, **kwargs):
current = time.time()
fps = 1 / (current - time.__previous)
time.__previous = current
print("%.1f" % fps) # Show only 1 decimal
job = om.MDGMessage.addTimeChangeCallback(callback, 'transform')
The additions to the time module were to maintain a reference to the previous_time variable, which apparently gets lost in a callback like this.
Output.
28.6
22.2
27.8
22.2
28.6
22.7
27.0
23.3
28.6
22.2
28.6
Alternatively, you could also use a script node, or an expression. Both of which are capable of listening in on timeChanged.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2BDEC120-2AB2-4625-BE4B-9BC342AFE10A%40gmail.com.