Maya Tidbits

Occasionanlly, in the course of answering a student question, I find myself creating a small example file or script. Here is where I'll post such examples as I make them, with a bit of explanation. Click on the thumbnail to download the corresponding file. Icons on the left are MEL scripts, those on the right are Maya scenes.

psShotList.mel A script to aid in setting up camera switching in Maya. It allows you to create and manage a visual list of the shots in your scene. It also creates a camera that animates (via stepped tangents) from the various positions of various cameras to simulate switching, allowing you to render out multiple shots all at once. See the top of the file for usage info.
normalizeLights.mel A small script that normalizes (scales them so they sum to 1 while maintaining the proportions) the intensities of all the lights in the scene.
psBlendControl.mel This script makes it easy to create 1D and 2D sliders with which to control blend shape targets. The sliders are created as NURBS shapes in the scene, and are automatically connected via a utility node to the specified target shapes.

Upon startup, the script displays a list of all blend shape nodes in the scene, and selecting a blend shape from the list will display all of its targets. To specify the controlled attribute, select it from the list and click on the "Set" button in either the 1D frame or the 2D frame.
saveJava3d.mel (v0.82) This script writes a java source file that displays the selected model, invokes the java compiler, creates a small html file to contain the applet, and exports the model itself as an OBJ. All of the files are organized into a folder at a user-specified location. This is just the first pass (hence the 0.8), as it still needs texture support and various other features, but it does function as is. Note that you have to have both Java and the java3d API (not just the SDK) installed on your system in order for the script to work. If you'd like to see an example of the result, click here (you'll need java and the java3d plugin).
psMakeGUI.mel This script was created to make it easy to make custom GUIs for animation without writing code. To get started, type in the name of the GUI and give it a width and a height in the "New GUI" section. Once you've done that, you can add buttons that will select objects by selecting the object and clicking the "Add Button" button. You can also add sliders to control attributes of objects- to do that expand the "Add Sliders" section and select the object. Type in the name of the (numerical) attribute, specify the minimum and maximum values, and click on the "Add Slider" button. Once you have a GUI that does what you want it to, you can add it to the scene as a script node in the "Add to Scene" section. The options there control when the GUI presents itself. It can either pop up every time the scene opens, or can be triggered by the selection of a set object. If you want to tie the GUI to selection, you can either select an object beforehand, or choose the "Name Object" option to type in the name of a specific object.
sJobList_AH.mel This script was written to make debugging scriptjob scripts easier. It lists all the script jobs in the scene in a selectable list. Jobs can be killed by clicking on them and clicking on the "kill" button. Killing a job with the script will cause it to automatically refresh the list, but you can also force it by clicking the "Refresh List" button.Since Maya has a lot of script jobs it uses, you can weed out the ones you're not interested in by clicking on one and using the "Set Limit" button. That will cause that script job, and all those listed above it, to dissappear from the list.
showFrames_AH.mel This script was created to address problems when using ghosting with objects with complex hierarchy/parental relationships. It will create copies of the selected object(s), either at two specific frames (useful for reference when creating an in-between pose), or X number of steps before and after the current frame, with the step size variable (as is the case with ghosting). The created objects are all placed in a group node, and a lambert shader is created and applied to all. Thereafter, the transparency of the shader (and therefore the reference objects) can be manipulated in the script GUI.
fillHole_AH.mel This script was created at the request of one of my students to mimick the P hotkey in lightwave. Select a polygonal surface and run the script. You'll then be able to create point-snapped polygons to fill holes in the surface, with the new faces automatically being combined (and vertices merged) upon hitting enter.
makeExp.mel This script simplifies the task of creating an expression to make a given attribute animate smoothly between minimum and maximum values, useful for secondary and ambient animation. To use, select an object that you wish to control via a sine wave and enter the name of the attribute to control in the text field (no dot needed). Specify a minimum and a maximum for the value to go between, and either enter a set speed, or choose the "add speed attribute" checkbox to add an animateable "speed" attribute to the selected object (with specified min and max values).
sillo.mel A script to aid in animation by providing a constant view of the sillouette of a character. It creates an orthographic camera positioned in front (positive along Z), with a parent group node. It opens a window providing a view through said camera, as well as a slider with which to rotate the camera about the origin. If you want the camera to move with the character, make the camera's group node (SillouetteCam) a child of the main transform of the character.
sourceScript.mel A handy little utility if you find yourself working on a lot of MEL scripts at once, as an alternative to creating a shelf button to source and run each script (which can clutter up your shelf). To use, start it up and type the name of the script you're currently working on into the text field. Thereafter, each time you click on the "SourceRun" button, that script will be both sourced and run. To change the target script, merely type in a new name (just the name, no MEL extension or path required), and click on the "Set Script" button.
stopwatch.mel: a script for tracking amount of time spent on a project. Clicking on the "Elapsed Time" button will display the amount of time (minutes & seconds) since the script was started, or since the "Reset start time" button was pressed.
curveCube.mel: a simple MEL script that creates cubes made up of NURBS curves at a user-specified size for use as controller objects.
A simple example of using soft bodies and a collision object to create an effect similar to stepping in mud or snow. A plane is created and made into a soft body. A second plane is placed underneath and made into a collision object to prevent the "mud" from sinking too low. Then, an object (in this case a cube) is made into a collision object as well and animated so that it intersects the ground, forming steps. To see it in action, hit play.
A script that allows objects to be duplicated along a curve. To use, select the object, shift-select the curve, and after applying settings, click the button
A scene that uses a combination of hierarchy, expressions, and motion path animation to create an animated bike system with pedaling and chain animation. For a more through explanation, grab the readme (right-click to save).
A scene in which an expression is used to randomly alter the intensity of a point light to simulate candle flicker. To look at the expression, open the file, go to Window->Animation Editors->Expression Editor. From there, select Select Filter->By Expression Name, and click on "flicker" in the expression list.
A script that will create a camera-locator pair such that the camera will not only point at the locator, but will automatically adjust its focus distance to the distance between it and the locator. The camera and locator are grouped together, and the camera has depth of field turned on automatically
An example of slightly more complex expressions- a walk cycle with 0 keyframes, just two sine waves and a few custom attributes. To look at the expression, open the expression editor and go to filter->By Expression Name, which will let you select the expression and view it. Selecting the root bone of the skeleton will reveal several custom attributes in the channel box that can be used to alter the motion.
An example of using an emitter with animated, instanced geometry to create a hail of bullets with "tracer" tails
An example of using an expression to drive the emission rate of a volume emitter in order to simulate a ball kicking up dust as it bounces.
A simple, straigtforward alternative to cloth for a simple waving flag. The flag is a NURBS surface created by lofting along a sequence of vertical curves. The second and fourth curves are animated with a sine wave expression to which an offset is applied, producing a waving motion.
An expression-driven animated tail, meant to mimmick dolphin/whale locomotion. Selecting the locator above the bones gives access to a boolean toggle for the motion as well as a speed value.
A script to aid in using Maya:Hair. Select a collection of hair curves and then a cross-sectional curves, and this script will extrude the cross-section along each hair curve and put all of the created surfaces on a display layer.
Another MEL script to help out with hair. Creates a locator tied to a selected CV on a dynamic curve to which objects can be constrained/parented. To use, select the CV of the "current position" curve and run the script.