"Asleep on the Job" (sequel) - Production Blog

Posts Tagged: mel

Text

A little script I found to add an object to a lattice that exists in your scene already:

Select the lattice, then the object.  Paste the following into the script editor, select all the code, and press numerical enter (that’s the enter by your keypad; the other big enter will add a new line but you want to execute the code):

string $selSet[] = `ls -sl`;

string $lattice = $selSet[0];

string $object = $selSet[1];

lattice -e -g $object $lattice;

Source: http://www.fuse-design.org/blog/tutorials-cg/how-to-maya-add-object-to-lattice-tutorial

Text

There are some locked nodes on our rigs (which is good usually, to stop accidental alterations especially within a team)… but occasionally I have to unlock them temporarily to futz with them.

I’ve finally made a simple shelf button to use the lockNode command with a selected object.  Posting here in case anyone finds it useful too:

//to lock a node

lockNode -lock(on) `ls -sl`;

// to unlock a node

lockNode -lock(off) `ls -sl`;

The ` is actually NOT a single quotation; it’s the little diddy thing next to your ‘1’ key on the keyboard. `ls -sl` is a typical way to refer to ‘all selected objects’.

You can do handy things like ‘apply this line of code to all selected objects’, and if you need to step through the objects one at a time you do this:

string $items[] = `ls -sl`; 
for ($x in $items) 
lockNode -lock(off) $x; 
}
Note that the above isn't necessary for the lock command (as the one liners earlier work too), just an example :)

Text

This is a beginner’s tutorial on finding a command you need in the MEL Command Reference, and running it in the script editor.  I’ll use deleting a namespace as an example, as it’s something I had to do recently.

Some background: I have shelf buttons which let me select a set of objects at once (eg: all of the character’s animation controls), and these all expect that the objects will be prefixed with “C_Nell_REF:”.  The prefix gets added automatically when I reference the Nell character file (C_Nell_REF.ma) into the shot scene, where the animation gets done.

This works great, until I removed the reference, and referenced a file with the same name back in (not a workflow I’m advocating; you should use ‘replace reference’ but I did this without thinking and it wasn’t undoable).  Maya did an annoying thing and left the first namespace there (but empty).  My new character had the prefix C_Nell_REF1:, because C_Nell_REF was already taken.  None of my shelf buttons worked anymore, grrr.

So how to remove the empty namespace then?

If you look up ‘namespace’ under Help > MEL Command Reference, you’ll see something like this:

namespace [-addNamespace string] [-exists string] [-force] [-moveNamespace string string] [-parent string] [-recurse] [-relativeNames boolean] [-removeNamespace string] [-rename string string] [-setNamespace string] [string]

The [square brackets] denote that something is an option. Words preceded by ‘-’ are called flags; describers of what the following italic item is for. Things in italics are info that you need to provide.  

So to remove the C_Nell_REF namespace, the script line looks like this:

namespace -removeNamespace “C_Nell_REF”;

(Note: the namespace you’re trying to delete does need to be empty first - you might need to select all items with the prefix “C_Nell_REF:”, and hit delete).

Easy, huh?  Enter that into the script editor, press ctrl+a (to select all the code), and hit numerical enter (that’s the vertical enter key on the right of your keyboard - it runs any code that is selected).

The final step after successful namespace removal was to go File > Reference Editor > C_Nell_REF, and change the namespace from C_Nell_REF1 to C_Nell_REF