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

Adding menus to your UIs


For more complex scripts, it can be helpful to add a drop-down menu to the top of your window. For example, you might want to have your script support custom configuration files and allow users to both save the current settings to disk, or to load previously saved settings. In that case, implementing the File menu with suboptions for Save and Load could be a very user-friendly option.

In this example, we'll be creating a window with its own menu, as well as looking at how to offer the user additional options via an option box, just like Maya's built-in menus.

How to do it...

Create a new script and name it customMenu.py. Once again, we'll be creating a custom class to handle both our UI creation and functionality:

import maya.cmds as cmds

class CustomMenu:

    def __init__(self):
        self.win = cmds.window(title="Menu Example", menuBar=True, widthHeight=(300,200))

        fileMenu = cmds.menu(label="File")
        loadOption = cmds.menuItem(label="Load")
    ...