variablespolygonpointsopenscad

openscad- use named variables in polygon points list?


I'm quite new to Openscad and have made a small program to create an instrument box with a sloping front. This now works quite nicely, so I want to "paramaterise" the size of the box & display cut-out so there's less mental gymnastics needed to make different size boxes..

What I have tried (and it doesn't work) is this (in part)- First the list of parameters for the outer shell of the box-

//Box outer shell
outer_start = "0.00,0.00";
outer_top_left = "0.00,30.00";
outer_top_right = "45.00,30.00";
outer_slope_bottom = "60.00,5.00";
outer_bottom_right = "60.00,0.00";

Then try to get them into the polygon points list-

polygon(points = [
[outer_start],
[outer_top_left],
[outer_top_right],
[outer_slope_bottom],
[outer_bottom_right]
]

And it doesn't work! Openscad doesn't show any errors, there's just no box drawn in the preview screen. If I manually enter the numbers in the points list, it works fine and draws the box exactly as I want it.

I have searched google and various mailing list with no results (that I could find) relevant to this, so can someone please put me out of my misery and tell me what I am doing wrong? Even better, how to do it right!

Thanks, Ken.


Solution

  • The points parameter of polygon has to be a vector of 2 element vectors (x- and y-value). So write your code this way:

    //Box outer shell
    outer_start = [0.00,0.00];
    outer_top_left = [0.00,30.00];
    outer_top_right = [45.00,30.00];
    outer_slope_bottom = [60.00,5.00];
    outer_bottom_right = [60.00,0.00];
    
    polygon(points = [
    outer_start,
    outer_top_left,
    outer_top_right,
    outer_slope_bottom,
    outer_bottom_right
    ]);