# OpenSCAD User Manual/Using OpenSCAD in a command line environment
### Command line usage

OpenSCAD can not only be used as a GUI, but also handles command line arguments.
OpenSCAD (DEV/nightly) 2025.02.05 has these options
Export help
OpenSCAD 2021.01 has these options:
OpenSCAD 2019.05 has these options:
OpenSCAD 2015.03-1 has these options:
OpenSCAD 2014.03+ has these options:
Openscad 2013.05 had these options:
Earlier releases had only these:
The usage on OpenSCAD version 2011.09.30 (now deprecated) was:

### Export options

When called with the -o option, OpenSCAD does not start the GUI, but executes the given file and exports to the output_file in a format depending on the extension (.stl / .off / .dxf, .csg).
Some versions use -s/-d/-o to determine the output file format instead; check with "openscad --help".
If the option -d is given in addition to an export command, all files accessed while building the mesh are written in the argument of -d in the syntax of a Makefile.
For at least 2015.03-2+, specifying the extension .echo causes openscad to produce a text file containing error messages and the output of all echo calls in filename as they would appear in the console window visible in the GUI. Multiple output files are not supported, so using this option you cannot also obtain the model that would have normally been generated.
Note: When exporting to STL, the GUI defaults to binary STL (smaller, faster) and the CLI defaults to ASCII STL (larger, slower). Post-processing pipelines may prefer ASCII STL; they should explicitly say `--export-format asciistl` in preparation for the default eventually changing to binary STL.

#### Camera and image output

For 2013.05+, the option to output a .png image was added. There are two types of cameras available for the generation of images.
The first camera type is a 'gimbal' camera that uses Euler angles, translation, and a camera distance, like OpenSCAD's GUI viewport display at the bottom of the OpenSCAD window.
The second camera type is a 'vector' camera, with an 'eye' camera location vector and a 'lookat' center vector.
--imgsize x,y chooses the .png dimensions and --projection chooses orthogonal or perspective, as in the GUI.
By default, cmdline .png output uses Preview mode (f5) with OpenCSG. For some situations it may be desirable to output the full render, with CGAL. This is done by adding '--render' as an option.

### Constants

In order to pre-define variables, use the -D option. It can be given repeatedly. Each occurrence of -D must be followed by an assignment. Unlike normal OpenSCAD assignments, these assignments don't define variables, but constants, which cannot be changed inside the program, and can thus be used to overwrite values defined in the program at export time.
If you want to assign the -D variable to another variable, the -D variable MUST be initialized in the main .scad program
without the first line, val would be undefined.
The right hand sides can be arbitrary OpenSCAD expressions, including mathematical operations and strings.
Be aware that your shell (bash, cmd, etc.) parses the arguments before passing them to openscad, therefore you need to properly quote or escape arguments with special characters like spaces or quotation marks. For example to assign a string production to a quality parameter one has to ensure the " characters OpenSCAD expects aren't stripped by the shell. In bash one could write:
or from the Windows prompt:
or you may need to escape the inner quotes instead:
Note that this sort of double-escaping isn't necessary when executing OpenSCAD from another process that isn't using a shell, because each argument is passed separately. For example a Java application might start a process like so:

### Command to build required files

In a complex build process, some missing files required by an OpenSCAD file can be generated if they are defined in a Makefile. If OpenSCAD is given the option -m make, it starts make file the first time it tries to access a missing file.

### Processing all .scad files in a folder

Example to convert all the .scad in a folder into .stl:
In a folder with .scad files, make a .bat file with text:
If it closes without processing, check to set the PATH by adding openscad directory to:
Add the openscad directory to the list

### Makefile example

The -d and -m options only make sense together. (-m without -d would not consider modified dependencies when building exports, -d without -m would require the files to be already built for the first run that generates the dependencies.)
Here is an example of a basic Makefile that creates an .stl file from an .scad file of the same name:
When make my_example.stl is run for the first time, it finds no .deps files, and must depend on my_example.scad. Because my_example.stl is not yet preset, it gets created unconditionally. If OpenSCAD finds missing files, it calls make to build them, and it lists all used files in my_example.stl.deps.
When make my_example.stl is called subsequently, it finds and includes my_example.stl.deps and check if any of the files listed there, including my_example.scad, changed since my_example.stl was built, based on their time stamps. Only if that is the case, it builds my_example.stl again.

#### Automatic targets

When building similar .stl files from a single .scad file, there is a way to automate that too:
All objects that are supposed to be exported automatically have to be defined in base.scad in an own module with their future file name (without the ".stl"), and have a comment like "// make me" in the line of the module definition. The "TARGETS=" line picks these out of the base file and creates the file names. These are built when make all (or make, for short) is called.
As the convention from the last example is to create the .stl files from .scad files of the same base name, for each of these files, an .scad file must be generated. This is done in the "%.scad:" paragraph; my_example.scad is a simple OpenSCAD file:
The ".SECONDARY" line is there to keep make from deleting the generated .scad files. Its presence helps determine which files no longer need to be rebuilt; please post ideas about what exactly goes wrong there (or how to fix it better) on the talk page!

### Windows notes

On Windows, openscad.com should be called from the command line as a wrapper for openscad.exe. This is because Openscad uses the 'devenv' solution to the Command-Line/GUI output issue. Typing 'openscad' at the cmd.exe prompt calls the .com program wrapper by default.

### MacOS notes

On MacOS the binary is normally hidden inside the App folder. If OpenSCAD is installed in the global Applications folder, it can be called from command line like in the following example that just shows the OpenSCAD version:
Alternatively, you may create a symbolic link to the binary to make calls from the command line easier:
Now you can call openscad directly without having to type in the full path.
On some versions of MacOS, you might get the following error when attempting to run openscad via that link:
You can fix this by creating a wrapper script to invoke the executable directly: