I have two questions about MEL programming, the first. If I want to declare an integer I must always use int, I can't type;
int $apple = "bbox"; // correct ? It must be;
int $apple = 54; // always a number, the same can be said for floats ?
What is meant by, MEL allows you to type commands in command syntax and function syntax ?
Replies
So what you want is to create an array and query the bounding box via xform (http://download.autodesk.com/us/maya/2010help/Commands/xform.html) :
float $bbox[] = `xform -q -bb "meshName"`;
See the ` ` that wraps the xform command? That's how you get data using MEL. I don't use MEL anymore, but when I did this was a good learning resource: https://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/mel/index.html#5
Hope this helps
I know, no one uses MEL, well, maybe not no one, before I move to python I want to learn some MEL !
And if you're not sure what a float is, do check Rob The Bloke's page : https://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/mel/DDATA_basic.html
Backticks is how you get data in MEL, what is the difference between
setAttr("mySphere1.translateX".10);
setAttr mySphere1.translateX 10;
==============================
$a = getAttr ("mySphere.translateX");
$b = `getAttr mySphere.translateY`;
Here's a good resource to get started with python.
http://www.chadvernon.com/blog/resources/python-scripting-for-maya-artists/
See the [] in the bbox float I made earlier? That signifies it's a list of numbers, or an array. If you look at what I previously typed:
float $bbox[] = `xform -q -bb "meshName"`; and apply it to mySphere you'll get this:
// Result: -1 -1 -1 1 1 1 //
While it "looks" like integers, they're not! This is what you get if you try:
int $bbox[] = `xform -q -bb "mySphere"`;
// Error: Line 1.11: Invalid redeclaration of variable "$bbox" as a different type. //
You need to be careful when you create variables in MEL otherwise you'll get errors like that.
As for:
$a = getAttr ("mySphere.translateX");
$b = `getAttr mySphere.translateY`;
I suppose they are the same, but I'd recommend you use the backticks: http://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/Commands/getAttr.html
Yes, I'd also recommend Python first. Chad's website is pretty good, I also recommend http://learnpythonthehardway.org/
// Result: -1 -1 -1 1 1 1 //
How do you know, what to declare as a float, int in MEL ? What about my int $apple = "bbox" variable, will Maya read it as a integer or a string ?
setAttr("mySphere1.translateX".10);
setAttr mySphere1.translateX 10;
==============================
$a = getAttr ("mySphere.translateX");
$b = `getAttr mySphere.translateY`;
What is different ?
Why isn't there a quoting system on this new forum update for polycount ?
"How do you know, what to declare as a float, int in MEL ? What about my int $apple = "bbox" variable, will Maya read it as a integer or a string ?"
I think for now, you'd be better off not explicitly declaring a type and let Maya assign it automatically. So...
$bat = 50;
$bbox = `xform -q -bb "mySphere"`;
and so on.
You can use whatIs to see what the resulting variable type is:
whatIs "$bat";// Result: int variable //
whatIs "$bbox";// Result: float[] variable //
If we look at int $apple = "bbox" - you are assigning a string to an integer variable so you won't get anything:
// Result: 0 //
// Result: int variable //
But.. if we allow Maya to automatically assign the variable:
$apple2 = "bbox";
whatIs "$apple2";
// Result: string variable //
As for getAttr/setAttr - I'd say just choose what works for you and stick with it to be consistent... but again I'd recommend using the ` ` to get data.
Honestly at this point, you should try a few examples, go through the MEL resources Autodesk provides, go through RobTheBloke and try some stuff and see how it works.. or maybe even try Python since there are more resources available to help understand data structures and flow etc
$bat = 50;
whatls "$bat"; // doesn't write a result, instead gives an error ?
I'm reading though some MEL resources, but I sometimes stumble across something to which I must ask a question
it will turn blue to indicate it's a recognized MEL command
float $a = 4.00;
whatIs "$a"; // Result: float variable //
string $b = (string)$a;
whatIs "$b"; // Result: string variable //
With Python you can - but with MEL nope.
MEL saves, even if not executed, code automatically to memory; that is why a variable can't be changed ?
Also nothing is actually saved into memory unless you execute the script. You can have dozens of lines and just highlight and execute one if you want. If you want to know what's loaded into memory use env: http://download.autodesk.com/us/maya/2009help/Commands/env.html
IDK about Python being the dark side. While I get why you want to start with MEL first, you might find it easier to pick up scripting with Python. There are a lot less quirks and it's more "standardized" per se. But honestly, whatever works for you - do you have any projects in mind? When I taught myself I basically had a tool (like auto-create basic collision meshes for exporting into Unreal) in mind and let that drive my learning