DeclaraCAD File

A DeclaraCAD file is a file with a .enaml extension. When one is created from within DeclaraCAD it will look like this:

# Created in DeclaraCAD
from declaracad.occ.api import *

enamldef Assembly(Part):
    attr width: float = 10.0
    Box: mybox:
        position = (0, 0, 0)
        dx = width

This just creates a simple 1 x 1 x 1 cube at the origin as shown below (the color depends on your settings).

Cube

The first line, # Created in DeclaraCAD is a comment. Just like in python everything after a # is a comment and is ignored.

The second line, from declaracad.occ.api import * is importing all of the DeclaraCAD declarations available in the declaracad.occ.api module. These are also listed in the Toolbox tab within DeclaraCAD. The toolbox pane can be expanded to see attributes that can be used.

Toolbox pane

The next line, enamldef Assembly(Part): is creating an "enamldef" named Assembly that extends the Part declaration. An "enamldef" is analogous to python's "class" and behave similary once defined. The name Assembly is special in DeclaraCAD. When DeclaraCAD opens a file it looks for the definition named Assembly and will render it into the viewer whenever the file is saved or run.

In DeclaraCAD every enamldef creates a single shape, with one exception. The Part is special as it can contain any number of shapes and when rendered will display each subshape (in this case the Box) individually.

The attr width: float = 10 is defining a new attribute. Similarly to a variable or attributes can be used for storing values or defining parameters your part can take.

Note: Within an enamldef block, enaml uses a lazily evaluated depedency graph. Unlike python, the order of references does not matter as long as there are no dependency loops. In the above example the width attribute could be after the Box node and still work as it looks "up" in the scope.

The Box: line is adding a Box (or Cube) into our part at position assigned on the next line. The mybox after the Box: is a reference designator that can be used to access that node and any attributes of it similar to any python variable.

That's about it in terms of special things that DeclaraCAD does, the rest is just python and enaml. If you haven't read up on enaml syntax, I suggest doing so as it's used throughout the docs here although it's quite easy to pick up just by looking at examples.

Let's now jump over to OpenCASCADE for a minute.