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 binary data


In this example, we'll look at how to read in binary data. We'll use our same example format, the "FOO binary" format, which consists of a header with three integers, followed by one or more entries, each of which has a string identifying a type of object and three or more numbers indicating its position (and possibly additional data).

Getting ready

In order to run this example, you'll need to have a .fob file at the ready. Creating binary files manually is a bit of a hassle, so I recommend using the example explained earlier to generate one for you.

How to do it...

Create a new file and add the following code:

import maya.cmds as cmds
import struct

def makeObject(objType, pos):

    newObj = None

    if (objType == "spr"):
        newObj = cmds.sphere()
    elif (objType == "cub"):
        newObj = cmds.polyCube()

    if (newObj != None):
        cmds.move(pos[0], pos[1], pos[2])



def readFOBFile():
    filePath = cmds.fileDialog2(fileMode=1, fileFilter="FOO binary files...