Build123d: A Python CAD programming library (github.com)

by Ivoah 64 comments 153 points
Read article View on HN

64 comments

[−] injidup 46d ago
These types of CAD scripting tools are great but always try to position themselves as an “alternative” to GUI-driven CAD, whereas in reality they are complementary. OnShape got it right with FeatureScript (https://cad.onshape.com/FsDoc/ ), which provides a very similar experience to Build123d at the scripting level. However, the insight that OnShape got right is that these scripts automatically become available as possible nodes within the history-based modeller. The OnShape UI is infinitely extendable beyond the fixed set of tools that comes with the base modeller.

Build an FOSS CAD front end using something like Build123d as the extension engine, and then add hooks so the user can select edges, surfaces, objects, etc., and feed them to inputs on the scripts. The output of the script is then the new state of the history-based modeller. That would be killer

[−] CountVonGuetzli 46d ago
I didn't know OnShape had such a feature. Will check it out!

What you describe is one of the main reasons why I use Rhino3D. It can be scripted via the Grasshopper plugin, which integrates really nicely with Rhino and its primitives. Sadly, Rhino isn't open source and is quite pricy

- https://www.rhino3d.com/ - https://www.grasshopper3d.com/

[−] injidup 46d ago
The fun thing is that onshape itself has a very thin kernel. Most of what you see as built in features are actually featurescript based. Onshape provides the source code for their built in feature set as a reference. https://cad.onshape.com/documents/12312312345abcabcabcdeff/w... You do need an account login ( free ) to view it.
[−] aaronblohowiak 46d ago
Kernel here is ambiguous.. I get what you mean, but parasolid is usually the thing described as the cad kernel.
[−] injidup 46d ago
You are right but I also kind of did mean it that way. I believe that Parasolid is at heart of Onshape, the true kernel. Then on top of that is a compatibility layer describing the set of low level operations available to featurescript. I'm sure that not everything in Parasolid is available to featurescript and perhaps there are some things added that are not in Parasolid. Featurescript also contains the selector/query logic for programatically picking geometry. Whether that comes from Parasolid I am not sure. I haven't worked with featurescript for a number of years now but when I did I was amazed. I managed to make an operation for taking any solid from the UI and generating customized interlocking ribbing. The idea was hollow surfboard design. It worked and I left it at that. Never built the surfboard!

However the downside with featurescript and I think a big mistake on their part was to use a custom language rather than python or javascript. Featurescript is almost javascript but with some syntax changes and magic DSL's. You are also forced to use the inbuilt editor which is horrible and if you have burned VIM keybinding into your nerve endings, going back to non modal editing is horrible.

Also the discovery of featurescript modules in the community has terrible UX. It's super weird that they have such a great system but finding useful extensions is horrible.

[−] rao-v 46d ago
I’d love to see this. It was a frustrating learning curve for me to realize that I couldn’t STEP export work from OpenSCAD to something like Fusion.

Build123d is much better (supports STEP export and import) but a tightly integrated CAD frontend would be ideal!

[−] WillAdams 46d ago
PythonSCAD now has STEP export:

https://github.com/pythonscad/pythonscad

[−] rao-v 46d ago
Wait to usefully import and export STEP you need to be BREP based right? I thought SCAD’s engine was fundamentally incompatible (only really one open source BREP engine out there - OpenCascade)
[−] WillAdams 46d ago
Pretty much, that's why for DXF export I rolled my own:

https://github.com/WillAdams/gcodepreview/blob/main/dxfexpor...

(shows a DXF w/ arcs)

https://github.com/WillAdams/gcodepreview/blob/main/gcpdxf.p...

(shows a .py file for making DXFs)

See the PDF at the top level for more information.

[−] Cargo4286 46d ago
Yes, AFAIK you are correct that SCAD is incapable of outputting clean STEP files.
[−] alnwlsn 46d ago
I think most GUI CADs have some kind of API like this. In FreeCAD it's Python. In Solidworks, it's VBA or C#. I don't think any are particularly well documented or supported by tutorials.
[−] unholiness 46d ago
Solidworks has VBA macros, which (on top of being poorly documented and unstable) subvert to the whole benefit of parametric CAD. Once you're creating features with a macro, you naturally want to edit them, but you also naturally want to rerun the macro itself to create them differently. It's like editing generated code and it's not a viable long-term setup.

FeatureScript is a different beast. It actually runs as part of regeneration in Onshape. Standard features (extrude, loft...) are also defined in FeatureScript, so your custom features are the same first-class citizens with a interactive GUIs and stable updates to upstream changes. You can freely mix interactive CAD and custom code by adding standard features and custom features.

[−] fainpul 46d ago

> runs as part of regeneration

You can do that in FreeCAD. Performance is horribly slow in my experience, but maybe I'm doing something wrong.

https://wiki.freecad.org/Scripted_objects

https://wiki.freecad.org/Create_a_FeaturePython_object_part_...

[−] luckypeter 46d ago
[dead]
[−] nakedneuron 46d ago
as someone mentioned recently somebody made this build123d-playground on the web:

https://jojain.github.io/build123d-sandbox/

learning curve is steep, but the examples get you going in no time..

though not really CAD, favorite example: https://build123d.readthedocs.io/en/latest/examples_1.html#c...

shows the ability of this implementation of the open cascade kernel.. i havent found this kind of projection function too often in other cad programs, so this is really cool.. i remember trying to do similar with ptc creo and it was a pain..

[−] Tagbert 46d ago
I used to do a lot with AutoLisp in AutoCAD back when it ran in DOS. Did a lot of dynamic creation and manipulation of the models with it. It was useful and a lot of fun (aside from parenthesis nesting).
[−] crispyambulance 46d ago
I use a scheme variant in an optics simulation product.

It's actually very pleasing to work with. I wish there was more stuff like this. Lispy programming languages and CAD seems like a natural fit.

That said, python is preferable for most people.

[−] antod 46d ago
I did that back in the 90s too. A modern IDE like set of features for lisp would've been awesome. Notepad on NT4 didn't cut it :)
[−] Tagbert 39d ago
yea, this was in DOS days.

On one project I was using autolisp in AutoCAD, Then another language in an external database, and some pascal work to tie them together. I had to segregate my work to separate days to keep from getting my syntax all screwed up.

[−] CarVac 46d ago
I like Build123d but I really want a hybrid mouse/code CAD built around it. I want to be able to click on entities and have them show up in the code editor instead of blindly trying to select edges.
[−] latenode 46d ago
CAD has needed a proper code-first workflow for years. The existing options always felt like they were built for the GUI first and scripting was bolted on after.
[−] contingencies 46d ago
Ahh, but can it do a clean self-reversing diamond thread including the reversing portion?

You'd be amazed how hard this is to achieve with open source tools. IIRC modern FreeCAD can't, old FreeCAD can, ~5 ways to achieve it in OpenSCAD don't work properly, Blender keeps shifting-sands and mostly can't but I believe the very latest can maybe do it with difficulty using geometry nodes.

[−] jpleger 46d ago
This is cool, seems like a next gen cadquery, which was really cool to see.
[−] htgb 46d ago
Despite being aware of its existence, I stuck with OpenSCAD out of habit. Only last week did I read through the documentation, and feel strongly that I've been missing out… it seems to solve all of my gripes with OpenSCAD. I'm excited to try it out!
[−] bvrmn 46d ago
Shameless plug: https://github.com/baverman/build123d_draft

Experimental extension to make code-cadding as terse as possible.

[−] torayeff 46d ago
My 2 cents: I fell in love with build123d (not at affiliated with build123d or gumyr) that I built a wrapper on top of it to generate both python code and export step stp 3mf. Please check here if you are interested texocad.ai
[−] z3ugma 46d ago
I have been using this library for a few months alongside Gemini 3.1 Fast

It's really useful to get an iteration loop going with an LLM.

The OCCP viewer extension for VS Code helps make sure you can see and manipulate the resulting model

[−] wisemanwillhear 46d ago
In many ways this looks fun. I love the precise control and programming power of tools like this, but when I need something in real life, I never use them any more. The productivity of graphical tools is so much greater (as far as my brain works).

When I was younger I used POVray for a few small projects, but once I had access to graphical interfaces the difference in output quantity and quality was huge. I still keep tools like POVray installed, but all I ever do with them is tinker once in a while.