I have a common design part in OpenSCAD defined by ca. 15 parameters. Is there a way how to put them to configuration files (or something similar) and choose between them conditionally?
I am looking for something like
type = "wide";
if (type == "narrow")
include <narrow.scad>;
else if (type == "wide">
include <wide.scad>;
else
include <round.scad>;
With file wide.scad containing data like
width = 200;
height = 50;
radius = 7;
etc.
I would like to provide the type parameter from commandline, which is possible via -D, but I cannot find a way how to bind the definition to parameter value.
I don't know of a way to put configurations into separate files, but I have solved a similar problems by putting configurations in a table of key-value pairs like this:
A couple helper functions can find the configuration you want from a table of key-value pairs.
To get a configuration:
Of course, you have to know which parameter is at which index in the configuration. Usually, I immediately unpack them into variables to given them meaningful names.
This works well enough once you've nailed down the parameters that will be part of a configuration. If the code you're writing it still evolving, it can become tedious to make sure you're using consistent indexes.