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

Making a basic window


All great user interfaces start with window. In this example, we'll be creating a simple window and using the text label control to add a simple message.

We'll end up with something like the following:

How to do it...

Start by creating a new file in your scripts directory and naming it basic Window.py.

Add the following code:

import maya.cmds as cmds

def showUI():
    myWin = cmds.window(title="Simple Window", widthHeight=(300, 200))
    cmds.columnLayout()
    cmds.text(label="Hello, Maya!")

    cmds.showWindow(myWin)

showUI()

If you run the script, you should see a small window containing the text Hello, Maya!.

How it works...

To create a window, you'll need to use the window command.

myWin = cmds.window(title="Simple Window", widthHeight=(300, 200))

While all of the arguments are optional, there are a few that you'll generally want to include by default. Here, we're setting the title to "Simple Window" and the size of the window to 300 pixels wide by 200 pixels tall. Also...