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