Export STL from OpenSCAD command line, calling module within script?


Given a .SCAD file which contains some modules, how can I execute one of those modules from the command line?


module One() { ... }
module Two() { ... }


openscad -q -o one.stl --module One example.scad

Note that there is no --module option, but that is what I'm attempting to do. The workaround would be to make another .SCAD file e.g. one.scad which includes example.scad, and simply calls One(); within and render that file from the shell file. But this is not ideal.

Josh M.

Posted 2020-11-29T19:48:50.620

Reputation: 135



OpenSCAD doesn't have such an option on the command line, but the general idiom I believe you want to use is have .scad source files which are modules include invocations of the module(s) at the top-level controllable by variables you can set on the command line or GUI customizer interface. Any such invocations will be ignored if the file is used (via use directive) in another file so they don't hurt its status as a library and make it easier to preview/test. So for example you could have:

wantOne = false;
if (wantOne) One();

and then set wantOne to true from the command line.


Posted 2020-11-29T19:48:50.620

Reputation: 5 311

Thanks. I think that is better than having a separate .scad just to call each module. – Josh M. – 2020-11-30T13:30:38.250