Book Image

Practical Maya Programming with Python

By : Robert Galanakis
Book Image

Practical Maya Programming with Python

By: Robert Galanakis

Overview of this book

Table of Contents (17 chapters)
Practical Maya Programming with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Learning the Maya Python API by example


Something like the Maya API is best explained through demonstration. Once you get the hang of it, the Maya API Reference and its copious examples will be a wonderful source of information. However, it will take some time and effort to become proficient. This section will present several easy-to-tackle problems to help illustrate the Maya Python API.

Converting a name to an MObject node

It's important to remember that when we step into the world of OpenMaya, we leave the Pythonic simplicity of PyMEL behind. The following line of code converts a node name string into a PyMEL PyNode:

>>> pmc.PyNode('mynode')
nt.Transform(u'mynode')

In the wonderful world of the Maya Python API, though, there is much more code involved to convert a string into the MObject instance that refers to the node:

>>> sellist = OpenMaya.MSelectionList() #(1)
>>> sellist.add('mynode') #(2)
>>> node = OpenMaya.MObject() #(3)
>>> sellist.getDependNode...