CADQUERY COMES of age
Now, we know what some of you are going to say — “Oh man, not another programmatic CAD tool, what’s wrong with OpenSCAD?” — and you may be right, but maybe hold on a bit and take a look at this one, because we think that it’s now pretty awesome! OpenSCAD is great, we use it all the time round these parts, but it is a bit, you know, odd in places. then along comes CadQuery, and blows it out of the water ease-of-use and functionality wise. Now, we’ve seen a few mentions of CadQuery over the years, and finally it’s become a full-blown toolset in its own right, complete with a graphical frontend/editor, CQ-editor. No odd dependencies on FreeCAD to be seen! That said, installing FreeCAD is not a bad thing either.
The goal is to have the CadQuery script that produces this object be as close as possible to the English phrase a human would use.
For those that haven’t seen it before, CadQuery is a python library that allows you to create 3D models, and export them as STL as well as STEP, so making models for your KiCAD project is an option too. Unlike OpenSCAD, however, CadQuery is much a lot more design–intent focussed. The idea is to have the python script read a lot more like a human description of the form of an object, rather than a bunch of algorithms constructing an object from straight boolean operations, all relative to the global coordinate system. CadQuery uses a relative association model, where things are defined relative to other things. From the docs:
CadQuery is different– you can locate features relative to others in a relative way– preserving the design intent just like a human would when creating a drawing or building an object.
STL file created by this code visualised in Microsoft 3D Builder
height = 60.0
width = 80.0
thickness = 10.0
diameter = 22.0
padding = 12.0
# make the base
result = cq.Workplane(“XY”).box(height, width, thickness)\
.faces(“>Z”).workplane().hole(diameter)\
.faces(“>Z”).workplane() \
.rect(height – padding,width – padding,forConstruction=True)\
.vertices()\
.cboreHole(2.4, 4.4, 2.1)\
.edges(“|Z”).fillet(2.0)
# Render the solid
show_object(result)
# Export
cq.exporters.export(result,’result.stl’)
cq.exporters.export(result,’result.step’)
We’re not saying OpenSCAD is bad, far from it, it’s just different, and for some people, CadQuery is going to be a lot much easier to get what you need done. need a fully-parameterised enclosure to 3D print? how about one done in just 47 lines of python code? As the complexity of the object grows, so does the benefit of the CadQuery approach. There’s a fair few concepts to learn with the tool, as it is pretty powerful, giving lots of ways to fix problems, but we think the effort will be well worth it. If you don’t like QC-editor, that’s no problem, as CadQuery can be used standalone with whatever editor you like, it even works with Jupyter notebook! Installing it also shouldn’t be an issue, with canned builds available, but that said, it’s a whopper of an install, so we hope you’ve got a spare gig of disk space!
If you are a a lot more visual thinker, and all this coding leaves you cold, then you might want to check out this guide to parametric modelling in FreeCAD, a similar guide for fusion360, or if you’re damned well sticking with OpenSCAD thank-you-very-much, then why not brush up on those OpenSCAD skills.
Thanks [JohnU] for the tip!