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

Accessing geometric data in polygonal models


In this example, we'll be looking at how to get information about polygonal geometry, which will form the basis for more complex scripts.

Getting ready

Create a new scene and make sure that it contains one or more polygonal objects.

How to do it...

Create a new script, name it polyStats.py, and add the following code:

import maya.cmds as cmds

# examine data for a currently-selected polygonal object
def getPolyData():
    selectedObjects = cmds.ls(selection=True)
    obj = selectedObjects[-1]

    vertNum = cmds.polyEvaluate(obj, vertex=True)
    print('Vertex Number: ',vertNum)

    edgeNum = cmds.polyEvaluate(obj, edge=True)
    print('Edge Number: ', edgeNum)

    faceNum = cmds.polyEvaluate(obj, face=True)
    print('Face Number: ',faceNum)

getPolyData()

Running the preceding code will result in information about the currently selected polygonal object being printed.

How it works...

The polyEvaluate command is pretty straightforward and can be used...