I essentially want to control Maya’s timeline through an external application, which I’m doing in a custom c++ command that calls a python callback defined by the user. This python callback then calls OpenMaya.MGlobals.viewFrame().
I’m getting a lot of weird viewport redraw issues using this method since these calls are essentially happening asynchronously and at very high speeds.
In retrospect doing silly stuff like for i in range(1000): OpenMaya.MGlobals.viewFrame(i) works absolutely fine since it’s properly waiting for viewFrame to finish before kicking off the next iteration.
I know it’s a long shot, but has anyone ever come across a scenario like this (advancing Maya time externally) and had it work properly?
Look at the motion capture server example in the Maya SDK. You can do this with a plugin but it’s easier to just have a python script attached to the commandPort command, listening for a message on TCP that says “go to frame X” or “advance one frame”.
This stackOverflow question gives an example of how to send a command over TCP to the commandPort:
in this case you’d send the cmds.currentTime( e=your_frame_here) instead of ‘polySphere’
And if I weren’t bound to a c++ plugin (that potentially calls python functions) due to technical restrictions I would have very likely gone for the python/TCP route. So cheers for the heads up!
However, I did manage to find the issue!
It would appear that manipulating global time (using MGlobals::viewFrame or MAnimControl::setCurrentTime) in the Maya API apparently NEEDS to be done in the main thread. The python callback I was raising, was raised in a different thread than the main thread. Changing global time in any other thread brings about a whole slew of issues when it comes to re-evaluating the DG graph.