Today I had to figure out how to get the current Maya version with MEL. I assumed it would be in some sort of environment variable but it turns out it had it's own command. I spent a good fifteen minutes trying to track this down so I hope this blog post can save somebody out there at least some of that time.
The command is
getApplicationVersionAsFloat.
float $mayaVersion = `getApplicationVersionAsFloat` ;
Why did you need to know the version? Did your script need to perform differently based on version?
ReplyDeleteIn this particular case I was working on my toolset where I have a small status window that tells me Maya version, Python version, and Pymel version. It's there because I want it to work on lots of different setups and computers and I want quick access to that information in case something stops working like it's suppose to. If you have plugins compiled for multiple versions, you may want to detect which version you're in and load the correct plugin automatically.
ReplyDeleteBesides that, there are some cases where you may be using commands on a per version basis, but not many. If you're using Python scripts, you may want to be able to tell if you're using 8.5 or above since prior to that there was no Python in Maya.
Not the MOST useful thing out there, but cool nonetheless. :)
ha. I was just trying to figure this out as well. spent about 2 minutes going through the docs and then googled and found this. need to know as I have a UI that gets docked on startup, but dockControl doesn't exist prior to 2011, so depending on maya version, it will either dockControl or showWindow. thanks!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI work with maya 2011 and the MEL gives me an error.
ReplyDeleteIt has to be written with a lowercase 'v' instead of an uppercase, like this:
float $mayaversion = `getApplicationVersionAsFloat` ;
Just tested with 2011 and I'm not getting the same error. No matter what command you are using the variable name is irrelevant, unless it's already being used for something else or is predefined as a different type. You can run the command without using a variable at all:
ReplyDeletee.g.: getApplicationVersionAsFloat ;
Check to make sure you hadn't already defined 'mayaVersion' as something else.
Thanks for this post Jay! I needed to query the version because certain built in maya scripts like doCreateGeometryCache have different numbers of arguments between 2011 and 2012.
ReplyDelete