-
Notifications
You must be signed in to change notification settings - Fork 49
Scripting guide
Matt Keeter edited this page May 23, 2013
·
5 revisions
In kokopelli, solid models are defined by Python scripts. A basic script has three main stages
- Import standard libraries
- Use functions from standard libraries to make shapes
- Assign shapes to output variables
Here is an example script with the three stages annotated
# Import the standard 2D shapes library
from koko.lib.shapes2d import *
# Use those functions to construct an output shape
c = circle(0, 0, 1)
for i in range(8):
c -= rotate(circle(0, 1, 0.2), i*360/8)
# Assign output variables
cad.shape = c
This script produces a pseudo-gear shape
There are three standard libraries, which can be examined in the Libraries menu.
Library | Description |
---|---|
koko.lib.shapes2d |
Flat shapes and transforms |
koko.lib.shapes3d |
Solid shapes and transforms |
koko.lib.text |
Sans-serif proportional font |
In general, these libraries contain two types of functions.
- Constructor functions take in a set of values (position, size, etc.) and return a shape (circle, triangle, cube, pyramid, etc.).
- Transform functions take in a shape and a set of parameters, and return a modified shape. Transforms include move, scale, rotate, taper, shear, etc.
The objects returned by these operations have overloaded arithmetic operators, so addition and subtraction performs computation solid geometry.
The global variable cad
defines what objects should be rendered, along with a few render settings.
Data attribute | Description | Valid values | Default |
---|---|---|---|
shape |
Single shape to render | MathTree |
None |
shapes |
Set of shapes to render | List or tuple of MathTree
|
Empty list |
border |
Size of empty border around model | Percentage (greater than 0) | 0.05 |
render_mode |
Force 2D or 3D render mode | '2D' or '3D' (string) | None |
mm_per_unit |
Real-world scale | Any value > 0 | 25.4 (setting for inch units) |
For example, to define a circle of radius 1", we could write the following
from koko.lib.shapes import circle
cad.function = circle(0, 0, 1)
cad.mm_per_unit = 25.4