Search processing.org:

Libraries

## DXF

This library writes all current triangle-based graphics (polygons, boxes, spheres, etc.) to a DXF file. It works with the beginRaw() and endRaw() functions. These functions will grab the shape data just before it is rendered to the screen. At this stage, your entire scene is nothing but a long list of lines and triangles. This means that a shape created with sphere() method will be made up of hundreds of triangles, rather than a single object.
Use something like a keyPressed() to trigger it, to avoid writing a file each time through draw(). Usually, the file will be saved to the sketch's folder. Use Sketch > Show Sketch Folder to see it from the Processing Environment.

A simple example of how to use:

    import processing.dxf.*;

    boolean record;

    void setup() {
      size(500, 500, P3D);
    }

    void keyPressed() {
      // use a key press so that it doesn't make a million files
      if (key == 'r') record = true;
    }

    void draw() {
      if (record) {
        beginRaw(DXF, "output.dxf");
      }

      // do all your drawing here

      if (record) {
        endRaw();
        record = false;
      }
    }