OpenSCAD is a great parametric-design CAD file.
It allows including libraries and other files into the main code file.
Which is fine for ordinary operation. Less fine for code distribution, especially for one-off use.
A single file without dependencies is then called for.
Can also allow freezing the functioning finished file and making it immune to library changes/updates.
mergescad.py was written.
The file is loaded into an array. Each time an include or use statement is encountered, the specified file is recursively loaded.
Only the variables/functions/modules used are extracted. Dead weight is left out.
Python was chosen for this level of complexity, as the startup time penalty is not worth the necessary cost of not spending too much time writing it all in C and bash is WAY too weak.
usage: mergescad.py [-h] [-q] [-o] [-F] [-O OUTFILE] [-L [LIBDIR]] [-t] [-T] [-I] [-a] [-A] [-d] file.scad merges together OpenSCAD source files positional arguments: file.scad input filename, OpenSCAD optional arguments: -h, --help show this help message and exit -q, --quiet print fewer details -o, --tofile output to filename.merged.scad instead to stdout -F, --nofiledet do not include date/size/name of source files to comments -O OUTFILE, --outfile OUTFILE output to specified filename instead to stdout -L [LIBDIR], --libdir [LIBDIR] add library directory (multiple possible) -t, --tracefile show directories searched for includes -T, --treefile show directories searched for includes, tree form -I, --treefileinc show includes in tree form, forces -T -a, --abspath show absolute paths, otherwise relative to input file -A, --listarr list internal array (debug) -d, --dryrun dry run, errors output only
The files aren't parsed in any artful way. Identifiers are extracted willy nilly from the code, after comments are removed. Then matching identifiers that look like modules or variables or functions are taken from the included file. Local variables/identifiers are handled as global (TODO...). False positives may happen.