Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Maya Programming with Python Cookbook

You're reading from   Maya Programming with Python Cookbook Master complex workflows and conquer the world with Python and Maya

Arrow left icon
Product type Paperback
Published in Jul 2016
Publisher Packt
ISBN-13 9781785283987
Length 266 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Pankaj K P Singh Pankaj K P Singh
Author Profile Icon Pankaj K P Singh
Pankaj K P Singh
 Herbez Herbez
Author Profile Icon Herbez
Herbez
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting Started with Maya 2. Creating User Interfaces FREE CHAPTER 3. Working with Geometry 4. Giving Things a Coat of Paint – UVs and Materials 5. Adding Controls – Scripting for Rigging 6. Making Things Move – Scripting for Animation 7. Scripting for Rendering 8. Working with File Input/Output 9. Communicating with the Web 10. Advanced Topics 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:

Retrieving input from controls

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:

Retrieving input from controls

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...
You have been reading a chapter from
Maya Programming with Python Cookbook
Published in: Jul 2016
Publisher: Packt
ISBN-13: 9781785283987
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime
Modal Close icon
Modal Close icon