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

Using script jobs to trigger custom functionality


Script jobs offer another alternative to explicitly calling scripts, or pressing buttons, to invoke your functionality. By using script jobs, it is possible to trigger custom functionality based on either a specific condition or a specific event.

In this example, we'll create a script job that will respond to the selection changed event by printing the name and type of the selected object to the console.

Getting ready

One of the things that makes script jobs so useful is the fact that they persist (as opposed to just running once). However, that can make developing scripts that use them a bit difficult, since if you change your code and re-run your script, you'll end up with multiple script jobs in your scene. For that reason, it's good to give yourself a way to easily clear out all existing script jobs. The following script will do just that:

import maya.cmds as cmds

def killAll():
    cmds.scriptJob(killAll=True, force=True)
    print('KILLED...