Maya Particles and MEL in the ballman piece

This tutorial was done in maya unlimited 4.0.
1. Create a curve skinned to your animated skeleton.
Rationale:
In my case, I created a curve that was skinned to the skeleton that was animated in my walk cycle. This curve that is created is to be the goal of the particles that are seen in the piece. This curve had a huge number of control points. When the particles were at their goal of the control point of the curve, they created a shape very similar to the original polygon model that was animated (the original model and the curve was not visible).
Particle goals are a feature in maya dynamics where the particles move toward these goals. A particle goal can be control points of curves or nurbs surfaces, polygon vertices, or other particles. Also, particles can move to specific uv cordinates on a nurbs surface or curve.
My animated model was polygons. Having particles at each vertex would not look good. The particles would be too regular on the surface, and there would not be enough coverage with just the polygon vertices.
If I converted my model to nurbs patches, there would be many patches. This would not work because particle can only have one goal object at a time. Even if there was only one nurbs model that I wanted the particles to define, there would be a similar coverage problem, as particles would map to control points. It would be possible to map particles between control points with uv cordinates for each particles. This was not a great choice because there is different densities of control points on a nurbs model, and the uv cordinates would have to be specified for each particles. This would be possible by assigning the particles random u v values to cover the entire model; however, once particles are in the desired density in the low density parts of the model (few control points per area), these particles might be in extremely high density in higher density parts of the model. This might affect the overall uniform appearance of the animated particles.
Particles can have the goal of other particles. Using particle/particle goals was not useful because particles can not be skinned to a skeleton.
What I did was to paint particles to the desired density over a model and essentially convert the particles positions into the curve. This gave me control over where the goal points were the the particle tool. There might be a more powerful and direct way of doing this with the script paint tool (but I did not know about this tool at the time).
1a. Make your model live, and paint particles to the desired density over it. (you left click to paint, and press enter when done and maya creates a particle object). You may have to do this several times cover everything properly (while you are painting it is hard to see what is going on at least with my graphics card). This will create a few different particle objects. You paint particles with the particle tool under the particle menu in dynamics.

while an object is live, it is wireframe and you can't tell very easilly which side of the model that the particles are on. It helps to have a duplicate of the model that isn't in live mode for this purpose. The current particles being painted aren't obscured by this model (on my video card).

once you have painted particles to the desired density, you will have several particle objects
1b. Execute this script makecurv.mel. It defines some global variables that store the particle positions and some functions to help you create the curve.
You must then run the function collectParticlePositions for each particle object that you created. Finally, you run the particlePositionsToCurve function to create the curve.
for example something like this would be typed into the script editor.
collectParticlePositions particle1;
collectParticlePositions particle2;
particlePositionsToCurve;

this should have created a curve with control points at all of the particles that you painted. Yes the curve is ugly, but it won't be visible in the final animation. Once you create the curve, you no longer need the particles or the original model, but you may want to keep them around just in case.
1c. Skin the curve to your animated skeleton. The bestway that I know to do this is to used rigid bind. Since we are skinning are curve, there is no way that I know of to paint weights for soft binding.
2. Create particles with goal that is the curve
2a. Create the particles
Look in the attribute editor at the number of spans that the curve that you created has.

You want to create that same number of particles. In the particle tool setting, you can set the number of particles to that value.

You now left click once and press enter. This will create a particle object with that number of particles.
2b. Set the goal.
Select the particles that you just created and the curve. Then go to particle->goal. There now should be goal attribute showing in the particles attributes.

If you press play on the animation timeline, the particles should move toward to controls points of your animated curve. Goal smoothness affects how quickly the particles will rest at their goal. If smoothness is 0, the particle with move to the goal immediately. If smoothness is high, the particle will oscillate a lot before sticking at the goal point. The parameter that is the name of the goal object controls the strenth of the goal weighting for that object.
2c. Initialize the particles
It may be useful to set goal smoothness to zero temporarily to get the particles to go the desired initial position. Once the particles are where you want them to start, select your particle object and go to solvers->initial state->set for selected.

this will cache the particle's initial position to your hard drive.
2d. Set particle type
Under you particle's attribute select blobby surface for the particle's render type. Click the current render type button. This should cause the attributes radius and threshold to appear below the button. If they do not appear, it may help to open and close the attribute editor.

Adjust the radius of you blobbies to the desired size. Threshold affect the size of the blobbies as well as how they interact when overlapping. To get a smoother look, you may want to increase both the radius and the threshold.
You now should have particles that are stuck to you animated model.
3. Fields
Fields are the main way to manipulate particle. I will show an example of creating a turbulence field.
3a. Create the field.
Under dynamics, go to fields->turbulence.
3b. Attach the field to you particle. Go to the dynamic relationships editor. Make sure that the field you created is highlighted under the particles that you are animating.

3c. Adjust field settings.

You can keyframe the fields attributes to get the desired affects. If you are not getting the desired effect, the magnitude of the field may be too low. Also, the particles goal smoothness should not be zero if fields are to affect the particles. Also, attenuation may prevent the field from having a strong enough affect further from the field. Frequency may also need to be adjusted to get the desired size of the turbulence waves.
4. Colliding with objects and GoalPP(goal per particle)
4a. Set particle to collide with the objects. Select the particle and then the object and then go to particle->make collide.

The objects that you selected should now appear under collisions in the dynamic relationships panel.
4b. Script Node.
If you are going to do this yourself and use my mel scripts, it may make your life easier to rename the particles that you animate particleShape5... otherwise you can change the name in all of the following mel scripts and expressions.
The script node that we will create will run every time the file is opened. This will do some initialization and define our particle collision routine.
To create the script node you open the expression editor. You then go to select filter->by script node name. You click the "new script node" button and it will create a blank space for a script node. Enter text similar to this mel script into the space and press the create button. You then need to select open/close in the "execute on:" drop box.

We create a global variable that holds the goal weights of each particle (which we wil set to goalPP attribute in an expression later). The myParticleHit function defines what our particles will do when they collide with an obstacle. In my file, the particles only break off from the model when they hit " nurbsPlane1". Notice the space at the front of the string. We will set up the collision event in the next step.
Instead of using a separate global for goalPP, it may be possible to manipulate the goalPP attribute of each particle indivually. It has been a while since I originally did this, and I suspect that it did not work right when I tried to set goalPP with the setParticleAttr command directly... I could be wrong... maya is weird sometimes.
speaking of weird. when setting up this tutorial, I had to put the definition of this runtime particle expression in the script node... otherwise I have to edit and save the expression when I opened it up from the file for it to have affect...
4c. Collsion Event
In order to create a collision event, you go to particle->particle collision events...
You click the new event button. And then put myParticleHit in the "event procedure" blank, and the press the create event button. The procedure myParticleHit was defined in the script node defined above(and should be redefined each time you open your file).
4d. goalPP
The goalPP attribute affects the contribution of goals per particle.Right click on goalPP of the particle object and create a runtime expression

In the following expression we set the goalPP attribute of this particle to our global goalPP variable unless we are initializing. If initializing we set them both to one which makes each particle attracted to our animated model (0 makes the particle ignore the model).

You can create this expression, or the script node script above should do it for you (if your particle is named particle5)... It is not wise to set the expression in the script node, because if you edit it, the script node will change it back next time you open the file. (I had to do this because of a bug). You can just edit the expression each time instead of having it in the script node... (or maybe you won't have the same bug).
5. Conclusion
I have described how you can have your particle group affected by an animated model, fields, and collision obstacles. This movie (divx codec) shows an animation from this maya project zipped (maya 4.0) which has all of this implemented. This should illuminate all of the tricks used in the ballman piece... the rest is just animation and more MEL.