Book Image

Maya Programming with Python Cookbook

By : Adrian Herbez
Book Image

Maya Programming with Python Cookbook

By: Adrian Herbez

Overview of this book

Maya is a 3D graphics and animation software, used to develop interactive 3D applications and games with stupendous visual effects. The Maya Programming with Python Cookbook is all about creating fast, powerful automation systems with minimum coding using Maya Python. With the help of insightful and essential recipes, this book will help you improve your modelling skills. Expand your development options and overcome scripting problems encountered whilst developing code in Maya. Right from the beginning, get solutions to complex development concerns faced when implementing as parts of build.
Table of Contents (17 chapters)
Maya Programming with Python Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Wrapping Python functionality in MEL


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.

Getting ready

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()

How to do it...

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...