[OpenSCAD] Configuration selection

Ronaldo rcmpersiano at gmail.com
Fri Sep 14 11:44:12 EDT 2018


​If you have many parameters for each alternative model, it is a good idea to
collect them in a list for each model.

modelA = [ ​1, // dim_a
               2, // dim_b
               [1,2]  // vec_a // some vector parameter
               ...
             ];
modelB = [ ​3, // dim_a
               4, // dim_b
               [2,3]  // vec_a
               ...
             ];
modelC = [ ​5, // dim_a
               6, // dim_b
               [3,4]  // vec_a
               ...
             ];

Then, select the parameter set with just one :? operator

modelset = model=='A' ? modelA : model=='B' ? modelB : modelC;

and retrieve the parameters from modelset:

dim_a = modelset[0];
dim_b = modelset[1];
vec_a = modelset[2];

With a few changes, you will be able to add more parameters without touching
the selection operation.

If the selection key 'model' is an integer instead of a char, you can even
avoid the :? operator at all.

modellist = [modelA, modelB, modelC];
...
modelset = modellist[model];




--
Sent from: http://forum.openscad.org/



More information about the Discuss mailing list