Skip to content
Matt Keeter edited this page Jun 8, 2013 · 4 revisions

Many of the example files from How to Make (Almost) Anything and Fab Academy are using an older version of the .cad file format. These files may not run in kokopelli without modifications.

Libraries

As an example, let's look at gik.cad from the computer-controlled cutting week. Many of the example files have a long header defining standard shapes. These definitions are incompatible with the new render path in kokopelli. You should delete the entire header (in this case, lines 21 through 901) and replace it with the line

    from koko.lib.shapes import *

If functions from the Python math library are used, you'll also need to add the line

    from math import *

or

    from math import sqrt, cos, sin, etc

(depending on what functions are used)

Bounds

The new render path automatically tracks object bounds (if the standard libraries are used). In addition, bounds are stored on a per-shape basis (rather than for the entire design file). This becomes relevant when working with multi-part models.

To adapt gik.cad, you can completely delete the lines

    #
    # define limits and parameters
    #
    cad.xmin = xstart - s # min x to render
    cad.xmax = x0 + r + s # max x to render
    cad.ymin = ystart - 4*dxy - s # min y to render
    cad.ymax = ystart + s # max y to render

or (to manually define bounds) replace them with

    #
    # define limits and parameters
    #
    gik.xmin = xstart - s # min x to render
    gik.xmax = x0 + r + s # max x to render
    gik.ymin = ystart - 4*dxy - s # min y to render
    gik.ymax = ystart + s # max y to render

Optional

The new shape libraries include overloaded arithmetic operators. For example, lines like

    slot = add(slot,reflect_y(right_triangle(0,w/2,c),0))

could be replaced by

   slot = slot + reflect_y(right_triangle(0,w/2,c),0)

to improve readability.

Summary

There are two main steps needed to port old files:

  • Switch from in-line libraries to koko.lib.shapes
  • Either remove bounds or make them object properties (rather than cad properties)
  • (Optionally switch from functional to arithmetic operators for addition and subtraction)

Have a look at the ported gik.cad.

Clone this wiki locally