First of all, what is it? OpenSCAD is an application for drawing printable 3D models. It is open source and you download it to your computer – so you will never lose your work because it has stopped being available or started charging. And it is different from other 3D drawing programs like TinkerCAD, Blender, Fusion360 etc. in that it is entirely text driven. This may put some people off, but for me it makes it much easier to be precise... but that's only the beginning, there's a huge amount of power here that makes it much easier to adjust and amend your drawings even once they have become quite complex.
So I thought I would start by showing how I have been drawing a wheel. Despite this, fortunately I managed to restrain myself from calling this thread "Why OpenSCAD is wheely good"...
To keep things simple I’m going to start by drawing a wheel. A very basic wheel, a bit of a rubbish wheel to be honest, but I want to demonstrate why I think OpenSCAD is powerful.
This wheel is essentially one cylinder sat on top of another cylinder with a hole down the middle... so it may not make for great running, but it should roll. We start by drawing our first cylinder. We use OpenSCAD's cylinder command, which draws a cylinder centred on the Z-axis. In a couple of lines of code we have our two cylinders - each cylinder is defined by the height and the radius at the base and top of the cylinder (which are the same here - but you can see you can also use the cylinder command to create cones).
Code: Select all
cylinder(6,10,10);
cylinder(1,12,12);
Now I want a 3mm hole down the middle for the axle - so I draw this in a similar way, but I'm going to subtract it from the cylinders I've drawn using the difference command:
Code: Select all
difference(){
cylinder(6,10,10);
cylinder(7,1.5,1.5);
}
difference(){
cylinder(1,12,12);
cylinder(2,1.5,1.5);
}
Ok, now I have something that should just about roll, although the cylinders have so many faces that it won't be smooth. Increase the number of faces by adding this line:
Code: Select all
$fn=100;
So far so fiddly. You could have done this a lot quicker in TinkerCAD, right? So here, then, is where I think the power lies: you've got a 20mm wheel and you want a 24mm wheel. Rather than starting from scratch, you reuse your old drawing. In TinkerCAD you can't just scale the entire drawing up (you still want a centre hole of 3mm and a flange depth of 2mm) so you have to adjust each of your cylinders separately. So, too, here, you have to edit the code in a couple of places... unless... you write your code using what OpenSCAD calls 'variables' (although programmers will recognise these as being more akin to constants). I'm going to call my variable 'radius' and set it to 10 at the start, but then whenever I want that value in the code I'll use the word rather than hard-coding in the specific value - something like this:
Code: Select all
radius=10;
difference(){
cylinder(6,radius,radius);
cylinder(7,1.5,1.5);
}
difference(){
cylinder(1,radius+2,radius+2);
cylinder(2,1.5,1.5);
}
$fn=100;
Notice that my wheel hasn't changed at all. But... by changing one single line of code I can create a wheel that is 24mm in diameter (or any other diameter I choose!)
Code: Select all
radius=12;
difference(){
cylinder(6,radius,radius);
cylinder(7,1.5,1.5);
}
difference(){
cylinder(1,radius+2,radius+2);
cylinder(2,1.5,1.5);
}
$fn=100;
Suddenly my drawing is a lot more reusable - and however complex it gets, changes can always be this easy!