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

Creating custom tools using contexts


Many of Maya's tools are used in an interactive manner, with the user specifying inputs as needed, and actions taking place either when the necessary number of inputs have been provided, or the user hits the Enter key.

So far, none of our scripts have worked this way—it has been necessary to have the user explicitly run the script, or press a button. That works fine for many things, but providing interactive input can add a lot of polish to a script. In this example, we'll be doing exactly that.

We'll create a script that, once invoked, prompts the user to select two or more objects. When they press the Enter key, we'll create a locator at the average position of all of the objects. To do that, we'll need to create a custom context to implement our very own tool.

Our custom tool in action. Left image is the tool while it's being used (notice the custom "AVG" icon on the left), and right image shows the result—a new locator at the average position of the...