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

Creating GUI to control all lights


Most scenes will end up containing multiple lights, and controlling them all can get to be a real hassle. In this example, we'll be creating GUI that will present the user with an easy way to control the colors of all the lights in the scene.

Running the script with three lights in the scene would result in something like the following:

Getting ready

Make sure that you have at least a few lights in your scene. Alternatively, use the three-point lighting example above to quickly set up a system of lights.

How to do it...

Create a new file and add the following code:

import maya.cmds as cmds
from functools import partial

class LightBoard():

    def __init__(self):

        self.lights = []
        self.lightControls = []
        self.lightNum = 0

        if (cmds.window("ahLightRig", exists=True)):
            cmds.deleteUI("ahLightRig")

        self.win = cmds.window("ahLightRig", title="Light Board")
        cmds.columnLayout()

        lights = cmds.ls(lights...