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.


The openscad -D option can actually include arbitrary code, not just variable definitions, so you can include a call to the module. You can even use /dev/null on Linux or NUL on Windows as the input file and have 100 % of your code in -D statements.

  • 1
    $\begingroup$ Maybe showing how exporting the STL works would benefit the answer. $\endgroup$
    – 0scar
    Apr 28 at 5:08
  • $\begingroup$ Yay! For the first time I was happy to see the -15 from my answer being unaccepted because the new answer is such good news! :-) $\endgroup$ Apr 28 at 16:37

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.

  • $\begingroup$ Thanks. I think that is better than having a separate .scad just to call each module. $\endgroup$
    – Josh M.
    Nov 30 '20 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.