[OpenSCAD] Question on defining a 'color' variable

Jess Askey jess at askey.org
Tue Jan 23 14:36:08 EST 2018

Hiya Folks…

Im doing some automation generating OpenSCAD files and I wanted to have my output .png objects colored based upon a value of another parameter…  In my simplistic dream world, I would do like below and put the logic in the .scad file. I could also try and deal with another step in my templating where I output the “myvar” variable directly, but I would prefer not to for various reasons if it is indeed possible in .scad.

The ‘_myvar’ parameter may have values of 1, 2 and 3 for example…

Im trying to do something like below, but I clearly have scope issues and Im confused…   Is there a way to accomplish this concept or am I barking up an empty tree?

_color = “black”;
if (_myvar == 1) _color = “red”;
else if (_myvar == 2) _color=”green”;
else if (_myvar == 3) _color = “blue”;

color(_color) cube();

NOTE: in this simple example, I would just put the ‘color(_color) cube()’ into the if/elseif blocks, but of course, in the real world, that is much more complex rendering so it doesn’t fit well inside of a large if/elseif tree.

Thank you…. Jess

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20180123/20b9ce16/attachment-0002.html>

More information about the Discuss mailing list