Can MEL be used to perform math equations

 10 October 2010 thegarland New Member portfolio Christopher Garland Modeler Merlil Productions Niagara Falls, USA Can MEL be used to perform math equations Hey guys, I have a new to perform certain equations numerous times. They're relatively simple equations, but it's a little tedious to work them out on paper over and over. So I'm trying to see if I can write a MEL script that will calculate the equation for me when I plug in certain variables. Kind of like a java applet. But I don't know anything about java programming, so I'm wondering if I can do it in MEL. These are the two equations: T = 2 * sqrt[ D/A ] where I get the value of T once I define D and A T = ((D - (A * t^2)) / (A * t)) + (2*t) where I get the value of T once I define D, A, and t Thanks. share quote
 10 October 2010 mduvekot Lord of the posts   Michiel Duvekot Owner THNKR Toronto, Canada sure.. first you'd declare a procedure, like this: proc float myProc (float \$D, float \$A) { if (\$A == 0) { error "Cannot divide by zero\n";} return 2 * sqrt(\$D/\$A); } If you save the procedure to one of the directories in the MAYA_SCRIPT_PATH, under the same name as the procedure, you can use it without having to declare it first, as Maya does it for you. In this example, I would save the code to myProc.mel in one of the script folders that I can find with getenv MAYA_SCRIPT_PATH; and then you can run your code: myProc 2 3; // Result: 1.632993 // __________________ Michiel http://thnkr.com share quote
 10 October 2010 NaughtyNathan HighEnd3D deserter   Naughty Nathan Technical Artist Sony SCEE Liverpool Manchester, United Kingdom of course you can do this kind of thing, it's practically the base functionality of all programming/scripting languages! it's also very easy, if fact it's almost exactly the same in python as you've written it out: # python from math import sqrt D = 0.5 A = 3.14 T = 2 * sqrt( D/A ) and here's how it would look in MEL seeing as how that's what you asked for: // MEL: float \$D = 0.5; float \$A = 3.14; float \$T = 2 * sqrt(\$D/\$A); :nathaN share quote
 10 October 2010 thegarland New Member portfolio Christopher Garland Modeler Merlil Productions Niagara Falls, USA Thanks a lot, guys! Both methods worked great. share quote
 10 October 2010 CGTalk Moderation Expert Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.