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).
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.
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...