# pcb-rnd - user manual

## 7.2 Export plugins

### 7.2.1 export_openscad

The openscad exporter generates the 3D model of the board in form of an openscad script.

The main entry point of the script is pcb_board(). All coordinates are in mm. The in x and y directions the 0;0 point of the board is the 0;0 point on screen in pcb-rnd, to make it easy to wrap the board in a translate() after measuring the coords of a point in pcb-rnd. The vertical origin is the middle of the board's FR4.

Supported features:

- arbitrary shaped outline
- top/bottom copper (optional)
- top/bottom mask (optional)
- top/bottom silk (optional)
- holes (optional)
- subcircuit (3d) models (optional)

#### 7.2.1.1 Subcircuit 3d models

Subcircuit models are loaded from external files referenced from the subcircuit in the pcb-rnd board file. Model files are searched recursively under the footprint library search path.

The subcircuit (footprint instance) can have the following openscad related attributes, all optional:

attrib | meaning
--- | ---
openscad=filename | file name of the .scad script (3d subcircuit model)
openscad-transformation=script | apply the specified transformation on the model instance
openscad-param=p1,p2,p3... | parameters to pass on to the model

If the openscad attribute is not present, no 3d model is inserted.

If openscad-transformation is specified, it is inserted before the model call; it typically contains a transform() and/or a rotate() to modify the placement of the model. The 0;0;0 point of the placement is the origin of the subcircuit in pcb-rnd, on the surface of the board. (Note: it is used to match the model to the footprint; subcircuit rotation and translation are automatically inserted by pcb-rnd on top of this. This attribute is empty or not present when the model lines up with the neutral state of the footprint.)

If openscad-param is specified, the module is called with this parameter list, else the model is called with empty parameter list.

A model file shall contain a single module, with "module" and the arbitrary module name in the same line, { in the following line. One instance of each model is copied into the output file so that the resulting openscad script has no external reference and is self-contained.

#### 7.2.1.2 no export objects

If an object shall not be exported to openscad, add the attribute noexport:openscad to it with value 1. This will omit the object only from the openscad export. Any drawing object can be omitted.

#### 7.2.1.3 namespace

By default all exported module names are prefixed by pcb_. When the openscad scripts of multiple boards are included in a complex project this would cause conflicts because of matching module names. This can be fixed by specifying a unique prefix on export using the prefix export option for each board.

#### 7.2.1.4 board thickness

The openscad exporter respects standard layer group thickness attributes when calculating board body thickness: it sums all insulating layers between top and bottom copper. Copper/silk/mask layer thickness is not respected because they would normally be too thin for reasonable openscad rendering.

If board thickness can not be determined, a fallback default value of 1.6mm is used.

#### 7.2.1.5 board origin

When exporing a board that would be part of a bigger 3d model it is important to be able to position the board properly in openscad. Normally the origin (0;0 coordinate of the openscad board model) will be the bottom left corner of the board's bounding box (when the board is looked down at from the top).

In many situations the board could be better positioned by an object, typically by a padstack (hole). This can be done by taking a drawing object and adding the openscad-origin attribute to it with the value of 1. When such an object is present on the board, the center point of the object is used as the openscad origin and the board model is translated so that the center point of the object is at 0;0.

If there are multiple openscad-origin objects present on the board, one is picked randomly.

#### 7.2.1.6 outline and cutouts

Board outline is either implicit or explicitly drawn on a boundary layer. In the second case, the outline is the centerline of the first closed loop of lines and arcs drawn on a boundary or mech layer. A closed loop means the endpoints of objects must match (using a reasonably large grid and object snap makes that easy) and there are no other overlaps or junctions. The first loop means the loop that contains the top-left boundary object in top view. That means if the drawing has multiple islands (boards) drawn, only the top-left island is exported.

When cutouts are enabled (on by default), any further layer objects on boundary layers ("outline" layers and "slot" layers; corresponding layer group types: boundary and mech) that are within the outline loop are considered. Only line and arc objects participate. Objects on the boundary ("outline") layer are assumed to be centerline-specified cutouts, line/arc thickness ignored. Objects on mech ("slot") layers are exported as cutouts with polygon approximation of their true shape (with thickness and typically round end cap).

Drilled holes and slots of padstacks are always exported.

There is no difference in rendering of plated and unplated holes/slots/cutouts.