6 ms·
Build123d: A Python CAD programming library
- injidup 6mo agoThese 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/ 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 6mo agoI 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.rhino3d.com/ - https://www.grasshopper3d.com/ https://www.grasshopper3d.com/
- injidup 6mo agoThe 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/a855e4161c814f2e9ab3698a/e/6f0c4f171ea09db350577341 https://cad.onshape.com/documents/12312312345abcabcabcdeff/w... You do need an account login ( free ) to view it.
- aaronblohowiak 6mo agoKernel here is ambiguous.. I get what you mean, but parasolid is usually the thing described as the cad kernel.
- injidup 6mo agoYou 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 6mo agoI’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 6mo agoPythonSCAD now has STEP export: https://github.com/pythonscad/pythonscad https://github.com/pythonscad/pythonscad
- rao-v 6mo agoWait 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)
- Cargo4286 6mo agoYes, AFAIK you are correct that SCAD is incapable of outputting clean STEP files.
- WillAdams 6mo agoPretty much, that's why for DXF export I rolled my own: https://github.com/WillAdams/gcodepreview/blob/main/dxfexport.dxf https://github.com/WillAdams/gcodepreview/blob/main/dxfexpor... (shows a DXF w/ arcs) https://github.com/WillAdams/gcodepreview/blob/main/gcpdxf.py 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.
- alnwlsn 6mo agoI 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.
- injidup 6mo agohttps://cad.onshape.com/FsDoc/ https://cad.onshape.com/FsDoc/
- unholiness 6mo agoSolidworks 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 6mo 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/Scripted_objects https://wiki.freecad.org/Create_a_FeaturePython_object_part_I https://wiki.freecad.org/Create_a_FeaturePython_object_part_...
- luckypeter 6mo ago[dead]
- htgb 6mo agoDespite 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!
- plumbees 6mo agoI've been wanting to get into OpenScad. Wondering what you've identified as an issue. I dabbled a little and I think I remember wishing it was more object oriented to make it a bit easier to make reusable adjustable pieces and I had found a python library that does openscad conversions; Wondering what gripes it solves for you.
- greenavocado 6mo agoB-rep (boundary representation) modelers (like build123d via OpenCascade) represent solids using faces, edges, topology geometry OpenSCAD uses Constructive Solid Geometry (CSG) which represents objects as boolean combinations of primitives (union, difference, intersection). It does not maintain an explicit boundary/face structure internally
- htgb 6mo agoOff the top of my head, in no particular order: As the sibling comment mentioned, the classic problem of chamfer/fillet. Inconvenient in OpenSCAD, trivial in build123d. There are various features I've missed: polylines with rounded corners, extruding along a path, and more I can't recall. As you mention: code organization. I didn't have the need early on, but over time I often wanted to do add custom things, for example my own hack of an implementation for extruding along a path. And passing data around is just painful and ugly... since you can't read any of your input shapes, you have to pass around all data explicitly -- alongside or instead of shapes -- and then only actually render them in the latest stage. Generally I found it hard to make reusable code, and generally it has to make many assumptions about the calling code. The OpenSCAD editor is one big IDE, and it's not a great one. My workflow was to keep VSCodium on one side and OpenSCAD on the other, just to use a better editor. I actually thought to myself that a good project direction would be to make it more modular and focus on the unique parts rather than the IDE. And that's indeed how build123d does it: primary repo only handles the rendering, and then suggest compatible viewers, with one shipped as a VS Code extension being the primary suggestion. Speaking of workflow, a huge difference is local coordinate systems: lacked in OpenSCAD and encouraged in build123d. It fits my brain really well. I just made a shape, now I want to make some holes in it. Previously I've often had to think about what global coordinates to put some volume, but now I'll just select that face and work with those local 2D coordinates. And another workflow annoyance before is when I'm designing something to be printed in separate parts. First, meticulously fit things together in the global coordinate system so that I can see them in the assembled state. Then to allow printing, also conditionally move all parts to manually specified other coordinates. With build123d one can define the parts separately, place joints in desired locations, and have them automatically snap together for the assembled view. It looks useful for integrating third-party parts as well. Minor thing, but I'm always slightly annoyed by the fact that a rectangle is called a square and a slab/box called a cube in OpenSCAD... Oh, and it's often useful to use polar coordinates. More passing around custom data and manually calling your custom conversion function whenever passing to OpenSCAD. build123d has first-party suitable objects for it. OpenSCAD development seems fairly dormant as well. Latest stable release was five (!) years ago, but by reading around you see that you're supposed to use the nightly version because it's superior. Not very friendly for newcomers. By contrast, build123d seems very active. I should stop now, because this already got pretty long. As you can see, I had some bottled up though -- thanks for letting me vent!
- CarVac 6mo agoI 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.
- Cargo4286 6mo agoThis feature technically already exists in build123d + OCP CAD Viewer (ocp_vscode). You can click a feature in GUI and it will copy the index to clipboard, you can then apply e.g. fillets to it on the code side. See here https://github.com/bernhard-42/vscode-ocp-cad-viewer/blob/main/docs/selector.md https://github.com/bernhard-42/vscode-ocp-cad-viewer/blob/ma... The biggest caveat is that there is currently absolutely zero mitigation for toponaming. This feature is extremely brittle, so I tend not to use it very much -- but I am still glad it exists for those situations when composing a selector is too annoying.
- mft_ 6mo agoAgree 100%. I've tried various code CADs before, and they're fine as long as what you're creating is simple enough to build from independent pieces, ideally that you can keep in your head. As soon as you need to refer to aspects that have been created within the CAD, like an edge, or a particular face of an extruded shape, the paradigm falls apart.
- bschwindHN 6mo agoI agree, I love code-based CAD but there needs to be a hybrid with GUI tools because selecting stuff with a mouse will almost always be easier. I known there is research out there (can't dig it up at the moment), but the goal would probably be to generate a robust geometric query for a selected item, so that small changes in the model don't affect which edge gets selected after subsequent operations. So if you extruded a face upwards, and then filleted all the edges at the top of that extrusion, this hybrid tool would generate a query which gives you all the top edges, instead of whatever the indices of those edges happens to be. I can't imagine it's an easy problem though to generate robust queries for all possible geometry a user might select.
- 6mo ago
- z3ugma 6mo agoI 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
- nakedneuron 6mo agolast time i tried, i didnt get the standalone mode to run.. there seems to have been an update in february, so i will give this another try when there's time.. (context: https://github.com/bernhard-42/vscode-ocp-cad-viewer/ https://github.com/bernhard-42/vscode-ocp-cad-viewer/)
- tonyarkles 6mo agodata point: standalone mode worked just fine for me a couple of weeks ago on an M4 MBP. Hadn't tried before so can't say if something got fixed.
- latenode 6mo agoCAD 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.
- IshKebab 6mo agoI disagree. Most CAD is inherently visual. These code-based systems work great for highly parametric and regular objects like fasteners and gears, or for procedural art, but those are really the tiny minority of CAD tasks. Most of the time you need to see what you're doing and click on stuff. Most CAD is more similar to graphic design, painting, etc. You wouldn't expect a "code first workflow" for Illustrator, and as far as I know nobody has ever successfully done anything like that. The closest I've seen are things like UI design tools that can generate code. But a) they usually suck, and b) that is a much simpler problem than CAD.
- hrmtst93837 6mo ago[flagged]
- IshKebab 6mo agoYeah that would be amazing, but sadly nobody has made that work for any CAD of reasonable complexity. In reality, CAD version control is done just like assets in the artistic world (game design, animation, films, etc): with file locks. I used to work for Dyson. There's no way you're designing a vacuum cleaner with code-based CAD. We used TeamCenter (which is probably the worst software I've ever used, but for unrelated reasons).
- rirze 6mo agoI mean, the CAD software, even though visual, has to retain some internal state of the model, right? It's possible, but I don't think there's enough pressure for these companies to support exposing that state to the user.
- nakedneuron 6mo agoas someone mentioned recently somebody made this build123d-playground on the web: https://jojain.github.io/build123d-sandbox/ 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#canadian-flag-blowing-in-the-wind 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..
- wisemanwillhear 6mo agoIn 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.
- bityard 6mo agoI remember running across POVray in the early 90's and not having a clue how to do anything more complex than a sphere with a light source. Some artists have done some truly magical things with it: https://hof.povray.org https://hof.povray.org
- tonyarkles 6mo agoOh my, thank you so much for bring back the POVray memories!
- jpleger 6mo agoThis is cool, seems like a next gen cadquery, which was really cool to see.
- Tagbert 6mo agoI 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).
- antod 6mo agoI 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 6mo agoyea, 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.
- crispyambulance 6mo agoI 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.
- copirate 6mo agoWhy do these tools never have the equivalent of sketch contraints in FreeCAD? That's how I build my models and it avoids a lot of math. I'd really like a "CAD as code" tool that's basically the FreeCAD Part Design workflow but with code. I know FreeCAD has a python interface but it's far from developer friendly.
- maouida 6mo agoI'm working on one with features you mentioned, with the main goal to make the workflow similar to mainstream CAD. Will release the first dev version in less than a month.
- htgb 6mo agobuild123d has constraints for avoiding math. I'm not familiar with the sketch constraints in FreeCAD though, how do they compare? https://build123d.readthedocs.io/en/latest/tutorial_constraints.html https://build123d.readthedocs.io/en/latest/tutorial_constrai...
- jwagenet 6mo agoThe reality is build123d is a fairly thin layer over the OCCT kernel with some pythonic affordances. I'm not sure OCCT has a robust constraint solver, so there is little development there. FreeCAD on the other hand (besides being significantly more mature) is also build on OCCT, but also does a lot on top of the kernel to make it more featured and stable.
- WillAdams 6mo agoWhen I've needed to solve for something in OpenSCAD I've just written a recursive module --- would that not work in Build123D?
- jwagenet 6mo agoParent was complaining about the lack of a built in sketch constraint solver in build123d, which is table stake feature of any "real" GUI CAD suite. build123d has some constraint options and you could probably use solvespace with it. Of course you can roll your own.
- torayeff 6mo agoMy 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
- contingencies 6mo agoAhh, 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.
- htgb 6mo agoDo you have an image of the reversing portion? Any examples of pitfalls? On the face of it, it seems like you'd define paths and sweep profiles for the material to remove. Is the difficulty in defining the path of the reversing portion, where it's not a helix?
- contingencies 6mo agoThreads have a range of properties, all of which must be supported, then it's generally the capacity to mirror a thread along the same face (exactly), and at either end add a transition zone that reverses, preferably with configurable characteristics (straight portion, rounding, etc.). Many approaches fail because the reversing transition zone is not readily aligned with the existing thread except through hacks or because reversing is incompatible with the programmatic approach used. Once that's all done, there are additional complexities for a captured element to ride in it which typically has a geometric relationship with the thread pitch, crossovers and transition zone. It's one of those "harder than it looks" problems, even for machinists. That's why, if the codebase can achieve it, I'd give it respect. PS. I also use a lot of OpenSCAD. Liked your comment. I started in POVRay so it made a lot of sense after managing non-FOSS CAD people for years.
- ruevs 6mo agoHad to Google this one :-) Since SolveSpace has a helix tool that can "extrude" any sketch along a helix it should be doable. https://www.linkedin.com/pulse/dreaded-double-helix-tutorial-self-reversing-screws-trevor-holloway https://www.linkedin.com/pulse/dreaded-double-helix-tutorial...
- bvrmn 6mo agoShameless plug: https://github.com/baverman/build123d_draft https://github.com/baverman/build123d_draft Experimental extension to make code-cadding as terse as possible.