Although Python is definitely the preferred way to go about scripting for Maya, there are some features that still require you to use MEL. We'll be seeing several of those features in this chapter, but first we'll need to look at how to call Python code from MEL.
First off, we'll need a Python script to call. You can either use something you've already written or make something new. For the sake of this example, I'll use a new script that simply creates a NURBS sphere at the origin, as follows:
# listing of pythonFromMel.py import maya.cmds as cmds def makeSphere(): cmds.sphere()
In this example, we'll create an MEL script that will in turn call our Python script. Create a new file and add the following code, being sure to save it with a .mel
extension. In this case, we'll create a file named melToPython.mel
:
global proc melToPython() { python "import pythonFromMel"; python "pythonFromMel.makeSphere()"; }
Note that...