![]() scad source to use color_selector( in place of color(. scad source, filling in the current color value for > add the color_selector module definition to the.Similar to our color_extractor approach above, we can define a “color_selector” module:Īny child elements wrapped by a color_selector module will only be evaluated (and therefore rendered) if the color specified matches the constant >.įor each of the colors we identified earlier using the color_extractor we can do the following: The next step is to actually render STL files for each of those colors we identified. It’s pretty easy to parse the RGB color values from that output. scad source by replacing instances of color( with color_extractor(, then running OpenSCAD will print out the fully-evaluated color values for each usage of color_extractor: To do this, we can define an extremely straightforward “color extractor” module to help: It’s clear that just reading the raw source code won’t work we need to actually run the code to evaluate expressions and variables. If we did a naive search for color() we’d end up extracting the string “really_cool_red” from inside the parenthesis, which is just a variable name and doesn’t actually tell us the RGB values! In the example above you could try simply searching for the color keyword and extracting the RGB value inside the parenthesis, but that approach falls apart for more sophisticated OpenSCAD models like this one: scad model and finding all unique colors. In order to automate per-color STL exports, we can start by reading the original. In the more complicated case we’d want to export two STL files: one for the 2x4x8 box and sphere which are both the same red color, and one for the 2x2x2 cube which should be rendered in green.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |