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

External module

Let's assume we want to use the LegoBrick from an external file.

Fortunately, this is simple! We just have to create a second file my_brick.µcad:

microcad create my_brick

The directory structure is supposed to contain these files:

lego_brick.µcad
my_brick.µcad

Let's add the following content to the my_brick.µcad file to create a few bricks with different parameters:

mod lego_brick;

use lego_brick::*;

// 2x2 double height
double_2x2 = LegoBrick(rows = 2, columns = 2, base_height = 9.6mm * 2);

// 4x2 single height
single_4x2 = LegoBrick(rows = 4, columns = 2);

// 3x2 one-third height
third_3x2 = LegoBrick(rows = 3, columns = 2, base_height = 3.2mm);

// generate geometry placing all elements side by side
use std::ops::translate;

single_4x2;
double_2x2.translate(y = -40mm);
third_3x2.translate(y = 40mm);

Picture

As you can see in the first line we use a mod statement to load our external module lego_brick.

Visibility

To make this work, we also need to change one line in our final part:

pub part LegoBrick(rows = 2, columns = 4, base_height = 9.6mm) {

Here we add the keyword pub to make LegoBrick visible from outside modules (like our my_brick.µcad):

Now you can export my_brick.µcad to generate the result of our tutorial.