View Full Version : MEL scripting death animtions? is it possible?

04 April 2003, 01:23 AM
I dont know much MEL, just some simple C++ commands but.... assume the following:
I have an animation of a bunch of simplistic characters... 99% of them are going to die by the main character's gun. So (heres the question) there a way I can set up a MEL script that will bring up this window when activated that has 1 button in it, that when I press it... will take the currently selected object (the character), create a particle emitter in the middle of it (the blood) with some specific settings, apply a shatter effect to the selected object (the corpse explosion), and then apply gravity to those pieces?

Maybe not those exact steps, but you see what im getting at... this way when I press the button, it keyframes maybe 15 or 20 frames of animation just by pressing this button.... so I could select somem character, press this button, and 20 frames letter he would be dead and have his corpse pieces fallin to the ground via gravity.

so, to simplify... I want a button that will automatically create, and then animate a particle emitter over 15 or 20 frames or so... and then also apply some effects to the selected object...etc...

Is this possible?
If you need a clarification I can easily try to help you out on anything your not understanding (its kinda hard for me to explain, so I wouldnt be surprised if no one could understand what I said)

(also, if you have AOL instant messanger, and have an answer for me... message me: Seuldieu. I want to talk to you! :D)

04 April 2003, 11:02 AM
Sure it's possible! It would be a MEL script, and probably not that complicated once you have done it by hand once.

-- Mark

04 April 2003, 07:02 AM
but I need a bit of help with it (kinda why I posted) ... how do I make something happen to the selected object... whats the MEL "variable name" for the currently selected object ??

04 April 2003, 09:19 AM
you can put a list of the currently selected objects in an array of strings with this command:

string $my_selection_list = `ls -selection`;

However, you're likely to have hundreds of questions like this along the way. Have you considered getting a good book on the topic of MEL scripting?? :D

-- Mark

04 April 2003, 04:38 AM
what? thats much too complicated...
whats the variable name for the currently select OBJECT (singular).... like $selection or something? thats what I wanna know...

04 April 2003, 05:19 AM
what? thats much too complicated...
whats the variable name for the currently select OBJECT (singular).... like $selection or something? thats what I wanna know...

Sorry to be the one to tell you this, but there is no other way than what I just described to you.

-- Mark

04 April 2003, 04:16 PM
Given that you're having difficulty with the complexity level of what might arguably be the most simple portion of your script, perhaps starting out with a smaller project to learn MEL is in order. You will need a fair amount of general MEL/coding knowledge to accomplish your task.

I second the idea of buying a book. Mark's own "MEL Scripting for Maya Animators" would be the ideal tool to help you on your way.


04 April 2003, 06:04 PM
I recently started the jump (or stagger) from c++ to MEL, too. I wholeheartedly agree that you should start with an easier script. Maybe try writing a window with a button that changes visibility or something. Then try writing a script that just creates the particle emitter. Then write one that keyframes character animation. see what I'm getting at? Baby steps...

04 April 2003, 10:00 PM
Hmm. It doesn't seem like the issue is complexity -- even the simplest scripts need to get the selection list.

I guess the point is: don't try to force MEL into working the way you think it should work. Attempt this and you'll go insane. Instead, bend like the willow, as David Carradine might have put it. Learn what the designers of MEL anticipated and follow that path first. :thumbsup:

string $my_selection[] = `ls -selection`;

That's how you get the selection. Period. If there's only one object selected, its name will be in the variable $my_selection[0] once you've done that.

-- Mark

04 April 2003, 11:39 AM
mark: plug plug plug!!

Gremlin: Once you've got your head round the basics of MEL, the best way to accomplish what you want to achieve is use the sript editor:

First save your scene. Take you character and actually do all the steps once by hand. When you've finished, open up the script editor, and all the commands used to do your process will be there. Copy the contents of the script editor out into notepad, then open up your scene again. Paste the script that's in notepad into the script editor and run it. Maya should now do the whole process for you (you might have to select your character first).

Now to make it work for any character you want you have to do some graft. Go through the script that you've got and learn about each command from the documentation: parameters and values it takes etc.

A lot of the stages that you've got so far will probably depend on you having the right object selected, which is not good. A lot of MEL commands will work by default on the selected object, but you can also pass them the name of the object you want to operate on as the last parameter. It is also important to note that commands that create or alter shapes will return the name of the node they create. So using this functionality you feed the result of one stage into the next like so:

$result1 = stage1Cmd -params values $someObjectIAmChanging;
$result2 = stage2Cmd -params values $result1;
$result3 = stage2Cmd -params values $result2;

And so on ad finitum.

After some sweating and cursing you should now have a script you can apply to any object to do the exact process you did by hand right at the start. So now you have to go back and make it interactive.

The simplest way to do this is to wrap the script up in a proc, to which you pass a long list of parameters that will control the final look (it's a good idea to do this from the start, to localise your variables otherwise you can get bugs that will force you to restart Maya before you can use the script again).

The best way to do this is to make a UI, which is a whole other topic in itself! Instead of passing a bunch of parameters in at execution-time, you give the user a UI with sliders and input fields that are connected by direct connections or expressions to attributes on the nodes you create and allow the user to modify the effect and watch the results unfold before them.

What you want to do is certainly possible, and is not very difficult once you know a bit of MEL, but I think you're going to have to invest a little time in learning MEL first. It could be a good idea to invest in a book such as "MEL Scripting for Maya Animators" (

Good luck!:)

04 April 2003, 11:53 AM
I hope you'll agree with me that the original poster could benefit from some exposure to working scripts at this point.

Anyway, I'm not sure what any of what you said has to do with finding what's selected, but it's all good information. :D

-- Mark

04 April 2003, 10:00 PM
yeah, buy mark's helped me a great deal. oh and then buy the david gould book, it goes into C++ stuff, which is what your interested in anyway. but start with mark's, because he's such a cool guy ;)


04 April 2003, 07:14 AM
I realize it may not be the best starting point to really get into MEL, but it'd be really helpful in my up coming animation (thus, the reason I asked)

but, I will get myself a MEL book, ill check out that mark book... thanks for everything guys.

CGTalk Moderation
01 January 2006, 11:00 PM
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.