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

Laying out UVs with Python


In this example, we will look at how to actually lay out UVs using Python. We will be applying planar, cylindrical, and spherical projections, each to a different subset of the faces of the selected object.

Getting ready

Make sure that you have a scene containing a polygonal object. We will be applying three different mappings to different parts of the object (selected by dividing the total number of faces by three), so it is best to have an object with at least a few dozen faces. If you do not have a model handy, make a polygonal sphere of at least 10 or so divisions along both height and axis.

How to do it...

Create a new script and add the following code:

import maya.cmds as cmds

def layoutUVs():

    selected = cmds.ls(selection=True)
    obj = selected[0]

    totalFaces = cmds.polyEvaluate(obj, face=True)

    oneThird = totalFaces/3

    startFace = 0
    endFace = oneThird - 1
    cmds.polyProjection(obj + '.f[' + str(startFace) + ':' + str(endFace) + ']',...