Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C++ Get frame rate

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
James_Viscira
1983 Views, 9 Replies

C++ Get frame rate

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();
9 REPLIES 9
Message 2 of 10
cheng_xi_li
in reply to: James_Viscira

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

Message 3 of 10
James_Viscira
in reply to: cheng_xi_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());
Message 4 of 10
James_Viscira
in reply to: cheng_xi_li

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);
Message 5 of 10
cheng_xi_li
in reply to: James_Viscira

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?

 

 timeslidersettings.png

 

Yours,

Li

Message 6 of 10
James_Viscira
in reply to: cheng_xi_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:

Capture.JPG

 

 

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.

Message 7 of 10

So I was able to cobble together a solution from the animFileExport example in the Devkit:

 

https://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=__cpp_ref_anim_export_util_2anim_file_export_8c...

 

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;
	}
}
Message 8 of 10
cheng_xi_li
in reply to: James_Viscira

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

Message 9 of 10
James_Viscira
in reply to: cheng_xi_li

Thank you for breaking that down Li.  I see what you're saying now.

Message 10 of 10
brent8S64J
in reply to: cheng_xi_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.

Post to forums  

Autodesk Design & Make Report