Defining the Mel Command
Adding your own functions into mel is a relatively simple thing to do. We have to derive our own class from MPxCommand which will handle the calls to our functions. In addition to the MPxCommand proxy class, we also have the MArgList, MArgDatabase and MSyntax utility classes which greatly simplify the process of parsing the arguments passed to the function. More on that later ;)
Right then, lets start with the simplest possible code for a new mel function. We simply need to provide a class derived from MPxCommand. This class then needs to impliment a doIt function to execute the required tasks, and we also need a creator function to return a new instance of our function class whenever the mel function is called.
As maya executes mel commands, it keeps an undo list of the last x number of commands executed (the exact amount specified in the user preferences). This basically means that when our command is called, a new instance of the MyCommand class is created. Later we will see that this is used to store a list of instructions to undo our command. For the moment though, we will not worry about undoing things, we'll keep it simple instead ;)