there are some sccripts at scriptspot (3dsmax) that do that, maybe with some scripting expierence you can transfer some of that structure to mel. For example I had a uv-script written in mel which I never saw before and was able to learn and transfer some of the concepts of that script.
if you're not able to write your own mel script, use this one. works like a charm. there's a free 'light' version or a pro version for purchase. http://www.renderheads.com/portfolio/UVAutoRatio/
I wrote a script to do this at work, it's not hugely complicated. However I am unable to share it here =( Considering there is some guy charging like $100 for a plugin to do this for Maya, I managed to write one which does the same thing in MEL in about half a day.
OK, here's a high level overview... Things you need: * A ratio to aim for (just an integer value, eg. 4 for 4:1 ratio) * The current object's texture width and height. My script defaults to 1024x1024 if the object's material doesn't have a valid texture. * An object with UVs! Steps: * Get selected UVs, or if none are…