Error-Checking In Preview Window for Customizable OpenSCAD Objects

Error-Checking In Preview Window for Customizable OpenSCAD Objects

thingiverse

The Thingiverse Customer supplies a range of input controls -- list boxes, sliders, etc. But it's missing some things. What if you want to make sure that a parameter is a number, but a slider or list box is inappropriate for the range of values? Or what if you need more complex error checking, like "these two parameters can't total more than 100"? You can check for this in your OpenSCAD code, but communicating the problem to the user is a pain, especially in an online environment like the Customizer where echo and assert don't necessarily work. This file lets you make a simple shape, but that's not the point. The point is to provide a relatively simple way to do parameter-checking and to show the results in a format that's guaranteed to be visible -- in the preview window. You can see how this works by using the Customizer to customize this object. Try breaking it, by leaving fields blank, or by setting things to negative or non-numeric values. If you do something that's not allowed, you'll see a message in the preview window explaining the problem. Here's how you use this approach in your own code: * Download the DisplayErrorsInPreview.scad file. * Include the appropriate parts of this code in your own OpenSCAD file. * Set the "assertions" vector to the appropriate error checks for your code. For each check, you'll just need to supply an OpenSCAD expression that returns true if that check passes and false if that check fails -- like "sides > 2" if the 'sides' variable should always be greater than 2 -- and an error message to display if the check fails. * Change your main drawing code to look like the sample below: if (anyassertionsfailed() { rotate([45,0,45]) showfailedassertions(); } else { dowhatyouactuallyneedtodotodrawyourobject(); } If you've customized the preview angle of your object, you'll want to change the parameters to the rotate; the .scad file comments tell you how to figure out what to use. Now, whenever the user changes parameter values in the Customizer, your error checks will run, and any errors will show up in the preview window, replacing your object. Even if someone downloads and manually changes the parameters in your .SCAD file, if they do it wrong, the error message will show up in their slicing/printer control software.

Download Model from thingiverse

With this file you will be able to print Error-Checking In Preview Window for Customizable OpenSCAD Objects with your 3D printer. Click on the button and save the file on your computer to work, edit or customize your design. You can also find more 3D designs for printers on Error-Checking In Preview Window for Customizable OpenSCAD Objects.