Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

OpenSCAD Power: Include and Import

With the tutorials we’ve done so far, it’s pretty easy to do the basics with OpenSCAD.  You can slap down some cubes, cut some drill holes in them and even create parametric .scad files that create parametric objects with only a few numbers from the end user.

But if you really want to start causing trouble, you’re going to need the power to remix.

Really, the ease with which models can be remixed and combined using OpenSCAD is what makes it so powerful.  Of course, any two files can be merged, and with modules it can even be done reasonably cleanly, but ideally, we want what the programmers have: include files.  One line of code that stands for all the code needed to do a task, however complex, so that we can box up each task, one after the other, and just move boxes around with minimal complexity at a given step.

No problem.  Take this file, name it ShellSphere.scad:

module ShellSphere(r, ratio1, ratio2){
scale([ratio1, ratio1, ratio2])sphere(r);
scale([ratio1, ratio2, ratio1])sphere(r);
scale([ratio2, ratio1, ratio1])sphere(r);

Now, in any file in the same directory, you can just call the library:

include <ShellSphere.scad>

Any module becomes a library.  Groups of libraries can be lumped together and pretty soon you’ve got BIG libraries.  I haven’t yet seen an OpenSCAD “standard library” for any type of task, but there totally should be.

And what of my beloved Blender?  What’s to become of mesh-modeled subdivided oddities?  Answer, import ‘em:

import_stl("mesh.stl", convexity=3);

Easy to do, and once you’ve got a manifold mesh (OpenSCAD will have trouble if it isn’t) you’ll be able to cut it, merge it, and generally fiddle around with it more or less worry free.  This can be a great tool flow for taking a nice ergonomic form factor made in Blender and putting utilitarian things like drill holes and mounting brackets on it…

Don't be the product, buy the product!