Python script for generating OpenSCAD boxes

by jbernardis, published

Python script for generating OpenSCAD boxes by jbernardis Feb 13, 2013

Thing Info

4458Views 399Downloads Found in Tool Holders & Boxes
Report Thing


I've always admired the laser cut boxes I've seen here and wondered whether or not it could be duplicated with 3D printers. I've seen boxes designed like this, but always for a specific purpose. I wanted the ability to create a box to the dimensions of my choosing.

To this end, I developed a python/tkinter script that allows you to specify box parameters and it generates clean OpenSCAD source code. Cut and paste the code right into OpenSCAD, hit F5, and you're just about ready to print.

Each face of the box is rendered with a separate module so that they can be printed one at a time allowing you to make further modifications, such as openings or mounting brackets.


The python script is standalone - no additional packages are necessary. It runs under python 2.7; it has not been tested with python 3.0.

The generated OpenSCAD program lays the faces out so that they do not overlap, but it makes no attempt to fit them onto your printer bed. That is left to you. Some people prefer plating everything at once; some people, myself included, prefer printing things one at a time.

The paramters you can provide to the program are: 1) internal dimensions - width, height, and depth. 2) how long and wide the tabs are, and how much space there can be between them (the span). You can also specify a "slop" paremeter which is used to make the slots slightly larger so that fit is not an issue. 3) You can specify the height and width of feet that are at the base of the front and rear faces. If either of these parameters is 0, no feet will be generated. 4) You can specify how many latch points are generated. The latch points are where M3 bolts can be inserted into the front and rear faces to hold the box together. You specify the number and whether the are along the top, bottom, or both. By default, these latch points are spaces equally across the width. Alternatively you can manually specify where the latch points should be.

Finally, once you have the parameters set the way you want, you can save that configuration, and then recall it later if you need to make modifications.

More from Tool Holders & Boxes

view more

Thing Info

4458Views 399Downloads Found in Tool Holders & Boxes
Report Thing

Liked By

View All

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag. Print Thing Tag

Very nice, but why not using openscad directly? You could change variables and quickly see variations in the design without having to copy and paste from python to openscad.

Once you have a working openscad script, I agree with you. But creating that first script is not so easy and it is very error-prone. The python eliminates (or perhaps only mitigates) that.

The script runs great von my laptop, but I can't copy text from the Box Creator ...Strg-c and left mouseclick doesn´t work in the Tk window... I use Ubuntu 12.04 LTS and Python 2.7.3!

I'm not sure why it works this way in Linux, but I changed the code so that the text box containing the SCAD code is not disabled. You can now copy it (desired behavior), but you can also change it (undesired behavior). Of course your changes are lost the next time the window is refreshed.

Ok it works ! Thanks !

Very nice, I definitely need to try this out. Thanks!