Edit:18 mars 2021, Cre:10 nov. 2019

OpenSCAD Library and Tools

In order to write my programs faster and also to make them more compact, I created a library that is now six years old and relatively stable as well as various other tools. I use it many times a week since its creation.

Language extension library

This library creates short commands and generalizes extrusion in all axes. Extrusion on native OpenSCAD is only possible along the Z axis, it is convenient to be able to do it along all axes. The extrusion axis is simply indicated at the end of the function name, for example to extrude a cylinder, we have the cylx (diam, length, x,y,z), cyly (diam, length, x,y,z) and cylz (diam, length, x,y,z) functions with x,y,z as cylinder position, which is the current position if these values are omitted.
There are abbreviated functions for translations, rotations and unions.
There are also various functions, especially mirrors (the most commonly used), duplication functions and even a set of functions for making pin and slot assemblies. There are also functions for the most common colours. In total, this library contains more than 70 functions.

Equipment libraries

This small library contains elements common in 3D printers:
Nema motors, small bearings, RC servos, fans and some other accessories.

Automatic generation of stl, dxf or images files in batch mode

I created a parts/files generator that allows you to export all the stl, dxf or png files of the model following the modification of a model. Unfortunately it is not possible to do this directly from OpenSCAD, so I use a batch windows program (.bat file) for this purpose. An OpenSCAD module has been created to generate the window batch programs (using OpenSCAD as a text generator with echo(); ).

An example of an application can be found here:

Workflow principle

  • Copy file “_batch_create.bat” in your project directory and adapt it with any text editor to your project (define your scad program, export directories and what exports you wish to do -stl, dxf, images, etc.)
  • Copy file “create_batch.scad” in your project directory and adapt it to your project with openscad editor (defines the parts you want to export and some options if needed)
  • Run “_batch_create.bat”, this will creates the Windows batches files based upon your data described in “create_batch.scad”. This will be typically one batch for stl files, one other for dxf files (if any), one for text (specification or bill of material) and one for images. For complex projects, you may prefer to have multiples stl batch generators.
  • Each time you want to recreates parts or images files after a modification, run the given batch file. You do not need to care about the ‘ECHO’ texts in the Windows batch files, they does’nt have any effect.

Note that you can only export 2D parts in dxf, so you shall do projections on the parts you want exports in dxf. For fast display, you may activate projection only when rendering (using the $preview parameter) with own projection function.

Note that the batch mode have seen recent improvements (2020) with the possibility to export with a different extensions and the possibility to export animation images. (See my own delta simulator program) for the explanations how to produce an animation film.
Specification or bom files can be created by exporting ‘echo’ files. For this to work, you need to filter the echo output (e.g. according if this is debugging, specification or Bill of Material echo) and select what echo is sent with a parameter (e.g. a special ‘part’ which only echo stuff without producing a model).
Some improvements to the Github files and processus are on the way (march 2021).

Translation macro

To be able to translate the legends of the Customizer customization panel or any other text (as can be sent by echo() for specifications or BOM) , I created a ‘Libre office’ macro, which replaces the lines in English with those in another language (by automatically commenting/decommenting) used for the most recent applications.

Only the commenting/decommenting process is automated, you shall write yourself the translated lines…

A note about OpenSCAD libraries.
There are many language or part libraries available, though they often tend to age and it is not very easy to find its way through.
A very interesting library is the ‘relativity’ library by Carl Davidson (that you may also find on Thingiverse, but it seems that Thingiverse mixed up the identity of the author). This library also have a quite exhaustive string library.
On Github:
As for 2021, while there was significant OpenSCAD evolution, the strings library seems still functional though you shall remove the extra-parameter in line 820 to stop a warning.
While the [List management→] may allow significant simplifications to such library, I did not found a more recent equivalent library.

(c) Pierre ROUZEAU
Privacy - Vie privée - Imprimable - Rechercher
Page mise à jour le 18/03/2021 17:33