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

Simple controls – making a button


Creating a window is only the beginning. In order to create a proper interface, we'll need to both add controls, and tie them to functionality. In this example, we'll be revisiting our good friend, the polyCube command, and tying it to a button press.

The resulting UI (and its output) will look similar to the following:

How to do it...

Create a new script and name it buttonExample.py. Add the following code:

import maya.cmds as cmds
def buttonFunction(args):
    cmds.polyCube()

def showUI():
    myWin = cmds.window(title="Button Example", widthHeight=(200, 200))
    cmds.columnLayout()
    cmds.button(label="Make Cube", command=buttonFunction)
    cmds.showWindow(myWin)
showUI()

Run the script, and you should see a 200 by 200 pixel window with a single button inside it. Pushing the button will create a polygonal cube with the default parameters.

How it works...

In order to trigger functionality from our UI, we'll first need to create a function to contain the...