[OpenSCAD] Configuration selection

Jordan Brown openscad at jordan.maileater.net
Fri Sep 14 18:01:58 EDT 2018


On 9/14/2018 8:44 AM, Ronaldo wrote:
> ​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;

That was what I was thinking, with a couple of additional notes...

I would try to align the definitions of model[ABC] into a table-like form:

    //         a  b  c
    modelA = [ ​1, 2, [1,2], ... ];
    modelB = [ ​3, 4, [2,3], ... ];
    modelC = [ ​5, 6, [3,4], ... ];

and if the number of variants is non-trivial, then do something similar
with the ?: sequence:

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

... though better would be to have the final "else" generate an error,
so that a typo doesn't silently give you the default.  I don't happen to
remember any good ways to do that, and don't have the time right now to
look.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20180914/9d5f3f26/attachment.html>


More information about the Discuss mailing list