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

Writing text files


In the previous example, we looked at how to read a custom data file format and use it to create geometry in a scene. In this example, we'll do the inverse, in that we'll examine our scene for polygonal cubes and NURBS spheres, and write the position of each one we find out to a new FOO file. In the process, we'll see how to write data to custom text-based formats.

Getting ready

Before running this example, make sure that you have a scene with some number of (NURBS) spheres and polygonal cubes in it. Make sure that you create the cubes and spheres with construction history enabled, otherwise our script won't be able to correctly identify the geometry.

How to do it...

Create a new file and add the following code:

import maya.cmds as cmds

def checkHistory(obj):
    history = cmds.listHistory(obj)

    geoType = ""

    for h in history:

        if (h.startswith("makeNurbSphere")):
            geoType = "spr"

        if (h.startswith("polyCube")):
            geoType = "cub...