My thoughts on OpenSCAD & Alternatives, and why CAD as code is cool
Purpose: This article will talk about my opinions about OpenSCAD, alternatives, and CAD as code as a novice. I want to jot my thoughts down here, but I acknowledge that there's still room for me to find a better solution/workflow than what I currently have.
The allure and drawbacks of OpenSCAD
Fusion360 is expensive. At $476 - $710 CAD a year, I could buy myself a new 3D printer rather than paying for a year of Fusion360. The monthly price of $90 also doesn't seem very appealing given how often I use CAD for my hobby. I also dislike alternative free cloud solutions since the terms and conditions can and will change if the company needs to increase revenue for the year. The logical conclusion then would be to find and use a free (in cost and in access) alternative.
One option would be to learn and use FreeCAD, though the UI isn't super fun to work with, and there's times where I'd like to express my thoughts code, but am unable to do so. A common example would be creating a grid of objects, easy to represent in a couple of `for` loops, less obvious to do in CAD programs, though this may just be due to lack of familiarity in said programs.
One very alluring option that came up was OpenSCAD, where all aspects of the 3D model are represented in code. While not everything has to be represented as code, I find it particularly useful for the following reasons:
- It's very easy copying and pasting features across projects
- Because you're forced to write everything in code, I find that my projects tend to be more parametric than in fusion, mostly because I don't have the escape hatch of directly modifying my feature.
- Coming from a software development background, writing code feels more confortable than finding the right UI/Tools that I need
- I make ortholinear keyboard cases in CAD, so the cases tend to be very simple geometrically speaking. Because of this it's very easy representing the keyboards as code
- Version control comes for free with git
While I like OpenSCAD very much, there's several roadbumps I've had with it that prevent it from being perfect. While I've had some luck in mitigating some roadbumps, there's still points that I'm considering to be near dealbreakers with OpenSCAD.
- OpenSCAD is famously very slow when there's lots of boolean operations. Without optimization on my end, all of my otholinear board cases have plenty of said boolean operations. By default, it can take a few minutes to render even with my Mac M1 processor.
- The dev/nightly release of OpenSCAD mostly mitigates against this with fairly good caching and optimization options
- OpenSCAD uses the CGAL kernel, which doesn't very easily allow for fillets.
- It's possible to use `hull` or `minkowski`, but it's quite frustrating having to go out of your way to write code that emulates fillets rather than just tossing on a `fillet` function
- One possibility is directly importing the direct OpenSCAD code into FreeCAD, and then adding fillets in that software.
- Biggest annoyance is occasionally I hit errors trying to import OpenSCAD into FreeCAD
- I don't think this is a fair point, but OpenSCAD doesn't have a free option for creating technical drawings easily, which is a bit of a downer for manufacturing
- I think this can be mitigated by importing the feature into FreeCAD, and then working off of that
- The most painful point: OpenSCAD cannot export STEP files directly
- This means that CNC manufactering + OpenSCAD by default is a no-go
- Also possible to try to import the OpenSCAD into FreeCAD, though doing so makes me anxious as there's effectively a risk that the translation fails, and if it fails, it means that all the work you've spent will have been for nothing.
While there's potential mitigations for the pitfalls of OpenSCAD, there's enough here to make it a bit cumbersome if you want fillets and/or the ability to CNC objects. For some projects, this is fine, but for keyboard cases, it's harder to want to go down this route.
CascadeStudio
Some alternatives I've investigated was CascadeStudio and CADquery.
CascadeStudio on paper is really nice, web browser environment, can export STEP files and easily do fillets thanks to it's underlying OpenCascade Brep kernel. While I personally preferred the declarative nature of OpenSCAD, using JS was fine. It even had cool features like using the VSCode text editor (Monaco) and intellisense.
The biggest issue I found with CascadeStudio is that it's horrible at error handling at all levels. If you accidentally passed in bad inputs (like an empty array) into CascadeStudio, it would bubble up the error message in the library without any context as to what caused the direct error to begin with. On top of this, it was also possible to have the OCCT webassembly fail and return an obtuse long integer error code. Compounded by the fact that there's no runtime type checking, using CascadeStudio eventually crawled to a halt, where each error I got forced me to undo the last three things I did in the hopes of fixing whatever the error was, since it was not remotely clear from the error message what went wrong.
Furthermore performance wasn't very good either. The cache was horrible, since it caused it's fair share of issues itself, and usually had to be disabled to prevent piling onto any debugging mess.
Ultimately while I think CascadeStudio does a lot of things right, I think it's biggest weakness is it's debuggability story. I think some easy wins for it would be adding basic input checking and error surfacing in it's functions. I'm not entirely sure what work would be involved in clarifying the long int errors that the opencascade.js kernel occasionally returns,though.
CadQuery
My best and last hope to an OpenSCAD alternative without coming up with external workflows would be CadQuery, a python library that also makes use of the OpenCascade kernel. CadQuery can also export STEP files and do fillets easily thanks to the kernel.
My biggest gripes with CadQuery initially are generally bikeshed-y and opinionated. One gripe is that you need to use conda to install to CadQuery, which can mess up your computer in certain situations. Thankfully there's instructions on how to use mini mamba to avoid this issue. Another issue is that it's purely a python library, which I dislike, because in theory anything you write in CadQuery is now coupled to a CadQuery version AND a python runtime version. Generally I think this shouldn't be too bad if you stick to a generally small subset of python, but it's not something I'm a fan of. The last biggest gripe with CadQuery is it's syntax. While OpenSCAD and CascadeStudio generally had a nice functional syntax and flow to it, CadQuery opts to have a syntax similar to jQuery. From an onlookers point of view, the functions in CadQuery are not very clear as to what they return. CadQuery also seems to have a way of reletive references, so it's possible to perform operations relative to given geometries. I've read that this can both make certain operations relatively nice and very difficult, depending on what needs to be done.
While the above has pushed me away from CadQuery, it is starting to look like potentially the best option of the three I have tried so far, and is something I want to try and hopefully adopt
Going forward
For now, I'm committing to trying CadQuery for my next enclosure and seeing how it goes. Ideally I can get past what I hope is superficial gripes with CadQuery and finally have a means of getting CNC ready models from code. If CadQuery gives me greif, the next thing to try might be going ahead with a solid OpenSCAD + FreeCAD workflow, or just begin to use FreeCAD entirely