OpenSCAD Intro

Instead of drawing an object in a traditional 3D drawing program, did you ever want to draw the object with a program?  If you answered yes; you are a looney! Oh and, OpenSCAD if for you.  I don’t think anyone would want to use OpenSCAD but there are some reasons that it is necessary.  First let’s talk about the good things before saying bad things about it.

First the syntax is quite elegant.  The number of 3D objects you can draw out right is tiny ( sphere, cube, cylinder and polyhedron) but using programming the objects can become anything.  Sure the polyhedron is technically any shape you could desire but drawing a shape using it seems impossible without physically drawing it on paper first.  So why are there so few shapes?  The answer is because you don’t need them.  I am even surprised that it even has cylinder because you can make a cube into a cylinder quite easily:

for (z=[1:360]) {rotate(z) cube([30,30,20], center = true);}

Sure it saves a bit of typing since this is the same cylinder:

cylinder(h=20,r=20, center=true)

cylinder

So what else is good about OpenSCAD?   Well there are shapes you can make with it that are just impossible or really hard to make with a traditional drawing program.  This is the main appeal to OpenSCAD.  Which brings me to why I am writing this post; I needed to draw a spiral.  For sure 123D Design just can’t do a spiral.  I would guess that AutoCAD can do it but I guess I just don’t know enough about it to even know where to start.  With OpenSCAD it is actually easy to do.  Logically all you have to do is start with a shape in his case a thin cube standing upright. Then all you do is place another cube of the same size next to it that is slightly rotated and slightly elevated.  Repeat adding cubes and a spiral will appear.  Programming this is OpenSCAD is really quite easy:

for ( z = [1:740]) {rotate(z*2) translate([0,0,z*.1]) rotate([90,0,0]) cube(size = [12,7,1], center = false);}

spiral

That’s it!  Really just 1 line of code and a loop and you get a spiral.  This seems quite easy right?  Well, yes and no.  OpenSCAD is great for things like this but when it comes to doing things that a traditional CAD program can do; moving objects on the screen and manipulating the object in 3D space, OpenSCAD falls flat on its face.

So what’s all this complaining I am doing it seems great right?  First I must say I don’t hate it.  But it’s only for very specific tasks.  When you need to draw something like a spiral it is great.  When you want a case for a raspberry pi don’t use it!  Is it impossible to draw a raspberry pi case in OpenSCAD? No of course not but it take a lot of unnecessary mental work to do it.  Let the computer keep track of the placement of 3d objects in space, use a program that you can grab and move them around.

Ok, enough ranting.  I am sure I haven’t even touched on half of the things I wanted to say but this post is getting really long.  On to the show!  Like I mentioned I had a need to draw a spiral and here is what I came up with:  (I am sure it can be more refined/simple but it works and I am not yet an expert at OpenScad) Sorry for the epic formatting fail Click here for the file: spiral1

difference(){union(){union(){difference(){

union(){

difference(){

union(){

difference(){

//spiral

for ( z = [1:740]) {

rotate(z*2) translate([0,0,z*.1])  rotate([90,0,0]) cube(size = [12,7,1], center = false);

}

}

}

translate([-20,-20,0]) cube([60,60,5]);

}

difference(){

union(){

//top finishing flare

for ( z = [0:50]) {

rotate(740*2) translate([0,z*.5,((z+740)*.1)+(z*.1)]) rotate([90,0,0]) cube(size = [12,6,1], center = false);

}

}

//cutting the end on the flare

rotate (45) translate([-40,10,75.02]) cube([60,60,20]);

}

}

//top angle cube

rotate([10,0,0]) translate([10,15,82.02]) cube([60,60,10], center = true);

}

}

union(){

//center cylinder

translate([0,0,5])cylinder(h=700*.1+6,r=3,$fn=100);

//rounded top

translate([0,0,700*.1+11])sphere(r=3,$fn=100);

}

}

//center hole

translate([0,0,5])cylinder(h=700*.1+11,r=1,$fn=100);

}

spiral1