I'm calling MAnimControl::PlaybackSpeed() to get my scenes frame rate. But I keep getting a value of 0 being returned. The docs say this value should be a double so I'm not sure what I'm doing wrong.
double fScenePlaybackSpeed = MAnimControl::playbackSpeed();
Solved! Go to Solution.
Solved by cheng_xi_li. Go to Solution.
Hi,
I can't reproduce this issue with Maya 2018 update 2, can you tell me your Maya version?
If you want to get the framerate(fps), it should be MTime::uiUnit.
Yours,
Li
Huh, interesting. I just assumed because the documentation said it was a double (although it doesn't specify what type it returns). So essentially I need to treat it like I do when getting Min/Max Time?
MTime sceneStartFrame = MAnimControl::minTime(); MTime sceneEndFrame = MAnimControl::maxTime(); double fSceneStartFrame = (int)sceneStartFrame.as(MTime::uiUnit()); double fSceneEndFrame = (int)sceneEndFrame.as(MTime::uiUnit());
OK, this didn't work either. I'm still getting back 0.
MTime sceneStartFrame = MAnimControl::minTime(); MTime sceneEndFrame = MAnimControl::maxTime(); MTime frameRate = MAnimControl::playbackSpeed(); double fSceneStartFrame = (int)sceneStartFrame.as(MTime::uiUnit()); double fSceneEndFrame = (int)sceneEndFrame.as(MTime::uiUnit()); double fFrameRate = (int)frameRate.as(MTime::uiUnit()); MGlobal::displayInfo( "Start Frame: " ); MGlobal::displayInfo(MString() + fSceneStartFrame); MGlobal::displayInfo( "End Frame: " ); MGlobal::displayInfo(MString() + fSceneEndFrame); MGlobal::displayInfo( "Frame Rate: " ); MGlobal::displayInfo(MString() + fFrameRate);
Hi,
I've tested your code and it seems working fine(I am just getting the double) with Maya 2018 Update 2. As I mentioned, it is based on MTime::uiUnit.The final fps is the result of uiUnit*playbackspeed.
You can set a custom value of 0 in timeslider to make playbackSpeed return 0. Could you check the timeslider settings?
Yours,
Li
Hi Li, I'm sorry but I'm not following. I just don't see how the FPS is derived from uiUnit*playbackspeed. I am testing on the default Maya scene.....basic settings. I am getting a return value of 6 from the uiUnit and a value of 0.0 from the playbackspeed.
This is what I am trying to get:
I don't understand why I would need to change anything in the preferences to get this through the API. I also don't understand why this is so difficult a value to pull from Maya. It's quite frustrating that such a small thing has been holding up my progress for days.
So I was able to cobble together a solution from the animFileExport example in the Devkit:
The solution is a bit too long to go through here. I essentially piggy backed on how they got the frame rate description (i.e. Film, Game, PAL, etc) and put the proper double value in with each description. I still have to say that this seems like a far too complex solution to get such a simple value from a scene. But now I can move forward!
Edit:
Here is the modification I did to the setToLongName functuion
/* static */ void FirstCommand::setToLongName(const MTime::Unit &unit, MString &name, double &frameRate) // // Description: // Sets the string with the long text name of the time unit. // { switch (unit) { case MTime::kGames: name.set(kGameTString); frameRate = 15.0; break; case MTime::kFilm: name.set(kFilmTString); frameRate = 24.0; break; case MTime::kPALFrame: name.set(kPalTString); frameRate = 25.0; break; case MTime::kNTSCFrame: name.set(kNtscTString); frameRate = 30.0; break; case MTime::kShowScan: name.set(kShowTString); frameRate = 48.0; break; case MTime::kPALField: name.set(kPalFTString); frameRate = 50.0; break; case MTime::kNTSCField: name.set(kNtscFTString); frameRate = 60.0; break; default: name.set(kUnknownTimeString); frameRate = 24.0; break; } }
Hi,
Because a user could put any fps inside preference which Maya ui does not provide(e.g. 1). So you might need to use playbackspeed * value uiUnit.
For example, if I put 1 inside playback speed in the preference|time silder when the 24 fps is selected ui. The real playback speed in MAYA when you click at the playback button will be 0.0416666666667 * 24 ~ 1 to achieve a desired 1 fps. So the MTime::uiUnit is kFilm and MAnimControl::playbackSpeed is 0.0416666667.
animExport doesn't care about playback speed in Maya, but you'll need to aware if you are working with playback in Maya.
Yours,
Li
This is the pythonic way but you should be able to work it out:
import maya.OpenMaya
fps = maya.OpenMaya.MTime(1, maya.OpenMaya.MTime.kSeconds).asUnits(maya.OpenMaya.MTime.uiUnit())
Can't find what you're looking for? Ask the community or share your knowledge.