Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Source Files

Source files are files that contain µcad source code. Such files must either have the extension .µcad, .mcad or .ucad.

A source file can include the following types of statements which we will all discuss within this book:

StatementPurposeExample
expressioncalculate valuesx * 5;
assignmentstore valuesy = x;
const assignmentnaming constantsconst Y = 1;
pub assignmentexporting constantspub Y = 1;
functionseparate calculationsfn f() { }
workbenchbuild or transform 2D sketches and 3D partspart P() { }
modulemodularization of complex codemod m { }
ifprocess conditionsif x > 1 { }
useuse symbols from other modulesuse m;
calluse functions and workbenchesf();
commentfor documentation// comment

In its simplest form, a µcad program consists of a single file containing one or more of the above statements.

A source file can serve as both a module and a workbench. You can use it to provide structure (for example, by organizing submodules) or as a kind of workbench where you add statements to generate outputs—such as a 2D graphic or a 3D model.

The workbench section of the file is only evaluated if it is in the main file (the one that microcad was called with).

The following examples illustrate this: a circle and a sphere are created, each with a radius of one centimeter.

test

// simply draw a circle
std::geo2d::Circle(radius = 1cm);

test

// simply draw a sphere
std::geo3d::Sphere(radius = 1cm);

Statements within a source file can represent either a 2D or a 3D model — but not both at the same time. Mixing 2D and 3D statements in the same file will result in an error:

test

std::geo2d::Circle(radius = 1cm);
std::geo3d::Sphere(radius = 1cm); // error: can't mix 2D and 3D

However, µcad programs can also be split across multiple files. To include other files, the mod statement is used...