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

Reading text files


In this example, we'll be reading a text file and using the contents to create some geometry in our scene.

Getting ready

In order to do any kind of file input/output, the first thing you'll need to do is to understand the file format that you're wanting to read (or create). In both this example and the one involving writing to text files, we'll be using an example file format—the "foo" file. "Foo" files are text-based files, and each line represents a geometric primitive of a given type, at a given location. The type of geometric primitive is represented by a three-letter string, with "spr" meaning a sphere and "cub" meaning a cube. The type string is then followed by three numbers representing the X, Y, and Z position of the item. So, an example .foo file might look something like the following:

spr    0    0    0
cub    -2   0    -2

Although this is certainly not a particularly useful format, it shares similarities with many common text-based formats. The OBJ format, for...