MatterCAD - Design Your 3D Parts In C#
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.
- Go into the 'MatterCadCommandLine' directory
- Copy one of the folders, we'll use the TrackConnector folder (select it and hit copy paste)
- Rename the folder to the new part you want to create. We'll use '10mmBox' for now
- Go into the new folder (double click '10mmBox')
- Open 'MatterCad.sln' (this should launch MonoDevelop)
- Open 'MatterCad.cs' from within the MonoDevelop
- Select the contents of the TrackConnector() function and replace them with 'return new Box(10, 10, 10);'
- Build and Run the program (we will assume you are making a debug build for now)
- Back in your file manager, go into the '10mmBox\bin\Debug' folder and open the file 'TrackConnector.scad' with OpenSCAD (you can give a differnt output file name in Main() later).
- Now to improve the design you would edit the code, run the program again and then just reload (F4) the part in OpenSCAD. Wash, Rinse and Repeat (do that over and over :).
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
- 3D Printing
- 3D Design
- Press Releases
- Small Business
- Jewelry Making
- Entertainment Industry
- MatterControl Touch
- ESD Materials
- Open Source
- Crafty Pen
- Digital Fabrication Anatomy
- How To
- Hardware and Upgrades
- Tips and Tricks
- Weekend Builds
- Top Ten
- Tech Breakdown
- Women in 3D Printing
- Project Ideas
- Advanced Materials
- Pulse Dual Extrusion
- Product Spotlight
- Military & Government
- Getting Started
- How To Succeed With Any 3D Printing Material
- Hacker of the Month