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 skeletons with script


In this example, we'll be looking at how to create skeletons with script. We'll create two examples, one simple chain of bones and one branching set, similar to what you might want for a creature's hand.

How to do it...

Create a new file and add the following code:

def createSimpleSkeleton(joints):
    '''
    Creates a simple skeleton as a single chain of bones
    ARGS:
        joints- the number of bones to create
    '''


    cmds.select(clear=True)

    bones = []
    pos = [0, 0, 0]

    for i in range(0, joints):
        pos[1] = i * 5
        bones.append(cmds.joint(p=pos))

    cmds.select(bones[0], replace=True)


def createHand(fingers, joints):
    '''
    Creates a set of 'fingers', each with a set number of joints
    ARGS:
        fingers- the number of joint chains to create
        joints- the number of bones per finger
    '''


    cmds.select(clear=True)

    baseJoint = cmds.joint(name='wrist', p=(0,0,0))

    fingerSpacing = 2
    palmLen...