CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 10-18-2010, 08:02 PM   #1
thegarland
New Member
portfolio
Christopher Garland
Modeler
Merlil Productions
Niagara Falls, USA
 
Join Date: Mar 2010
Posts: 12
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.
 
Old 10-18-2010, 09:04 PM   #2
mduvekot
Lord of the posts
 
mduvekot's Avatar
Michiel Duvekot
Owner
THNKR
Toronto, Canada
 
Join Date: Dec 2003
Posts: 1,063
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
 
Old 10-18-2010, 09:07 PM   #3
NaughtyNathan
HighEnd3D deserter
 
NaughtyNathan's Avatar
Naughty Nathan
Technical Artist
Sony SCEE Liverpool
Manchester, United Kingdom
 
Join Date: May 2008
Posts: 2,608
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:

Code:
# 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:

Code:
// MEL: float $D = 0.5; float $A = 3.14; float $T = 2 * sqrt($D/$A);
:nathaN
 
Old 10-18-2010, 10:15 PM   #4
thegarland
New Member
portfolio
Christopher Garland
Modeler
Merlil Productions
Niagara Falls, USA
 
Join Date: Mar 2010
Posts: 12
Thanks a lot, guys! Both methods worked great.
 
Old 10-18-2010, 10:15 PM   #5
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:58 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.