Nov. 28, 2012
Any programmer wanting or needing to model custom 3D parts has probably stumbled across OpenSCAD, a program that allows you to generate parts using basic scripting. OpenSCAD is a wonderful tool and for a while we used it exclusively in designing parts, but we missed the ability to use a fully featured programming language. Eventually we started creating a homegrown utility that would allow us to write a part using C# - we call the utility MatterCAD. For our design workflow we use MatterCAD to output a .scad file which we can then open in OpenSCAD. OpenSCAD is used to do the visualization and to do the final outputting of a printable .stl file.
Over time MatterCAD has continued to advance to the point were it is probably useful and stable enough to be made generaly available.
MatterCAD is designed to make the creation of parts easier with two main features. The first feature is the ability to treat each part, or collection of parts, as distinct objects in the code. Treating each part as an object allows information to be stored about the part - attributes like its bounding box, position and transforms. The other main feature is a rich set of positioning tools, such as 'align' and 'set center'. With these positioning tools you can define parts relative to each other or to a specific coordinate position in the world. For example you can align the bottom of a part with the Z 0 plane of the world, that way you can be sure that part will always stay at Z 0 regardless of the changes you make to its design. With 'align' you can also layout parts relative to other parts. Again, when you change the size or position of one part, all the parts that are aligned to it simply move to their correct positions relative to the one that has changed.
Resources You Will Need:
You will also need an IDE (integrated development environment) to edit the code. We recomend you use MonoDevelop. MonoDevelop is available for Windows, Mac and Linux. You can also use VisualStudio if you have it but it is not as easy for everyone to get.
You will want to look at the API for MatterCAD.
And finally you will need a copy of OpenSCAD to view your part and to output it to an .stl for printing.
Here is a very simple script. It is a track connector for a wooden train set.
using System; // we need some usings to get started
using MatterHackers.Csg; // our constructive solid geometry base classes
using MatterHackers.VectorMath; // helper math functions
static class SimplePartTester
static CsgObject TrackConnecor()
// CsgObject is our base class for all constructive solid geometry primitives
// we create a box object and name it bar, the "link" is the name it will
// have in OpenSCAD
CsgObject bar = new Box(20, 5.8, 12, "link");
// we set it's center to the center of the coordinate system
bar = new SetCenter(bar, Vector3.Zero);
// and we make the total = bar, the only object we have at this time
total = bar;
// now we make a cyliner for one side
CsgObject leftHold = new Cylinder(11.7 / 2, 12, Alignment.z);
// position it where we want it
leftHold = new SetCenter(leftHold, bar.GetCenter() + new Vector3(12, 0, 0));
// and make another one on the other side by mirroring
CsgObject rightHold = leftHold.NewMirrorAccrossX();
// this is the way we actually decide what boolean operation to use to put them together
total += leftHold;
total += rightHold;
return total; // and pass it back to the caller
static void Main()
// an internal function to save as an .scad file
Get The Latest From MatterHackers
Please enter a valid email.