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

Retrieving input from controls


While you will often need to add one-way controls (such as buttons) that trigger functions upon user input, you will also often need to retrieve information from the user before taking an action. In this example, we'll be looking at how to grab input from field controls, in both integer and float varieties.

The finished script will create a given number of polygonal spheres, each with a given radius. The resulting UI will look like the following:

Pressing the Make Spheres button with the previously mentioned settings of 4 spheres at a radius of 0.5 units each will result in a line of spheres along the x-axis:

How to do it...

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

import maya.cmds as cmds

global sphereCountField
global sphereRadiusField

def showUI():
    global sphereCountField
    global sphereRadiusField

    myWin = cmds.window(title="Make Spheres", widthHeight=(300, 200))
    cmds.columnLayout()
    sphereCountField = cmds.intField...