Command Line Arguments in OpenSCAD
Command-line arguments are a common way to parameterize execution of programs. For example, openscad my_model.scad -o output.stl
uses my_model.scad
and -o output.stl
arguments to the openscad
program.
To experiment with command-line arguments in OpenSCAD, you can run the script from the command line:
This will set variable1
to 15 and output the result to output.stl
.
OpenSCAD doesn’t provide direct access to raw command-line arguments like some other languages. Instead, it uses a system of special variables and command-line defined variables to achieve similar functionality.
The $0
variable provides the name of the current script, similar to how other languages might provide the program name as the first argument.
The $user_variables
array contains all variables defined on the command line, which you can iterate over or access individually.
Custom variables like variable1
can be defined in the script and optionally overridden from the command line, allowing for parameterization of your models.
Next, we’ll look at more advanced ways to parameterize OpenSCAD models using modules and functions.