Live data from Hacker News

Build123d: A Python CAD programming library

github.com

61–67 of 67 posts

Re: Build123d: A Python CAD programming library

#61

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.

build123d can absolutely accomplish this. I downloaded a STEP file of a self-reversing (diamond) thread part from McMaster Carr for analysis. I will reply when I finish a recreation of it. Based on my analysis of the STEP I most likely will start with a regular left and right helices that are trimmed slightly before they intersect at the end. From there will need to apply constraints for tangency with the helices while staying fixed on the cylindrical body. There are multiple ways to achieve this. The next step is to perform a sweep (cut) on half of the transition plus one side of the helix. This can be done in two stages to avoid self intersecting sweep geometry (a big no-no in most/all BREP CAD kernels).

Re: Build123d: A Python CAD programming library

#62
post #4

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.

I 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 extrud…

> 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.

There is quite a bit of research that this is impossible. No matter what algorithm or heuristic you use, the second that symmetry is introduced, the query breaks down. The only way to resolve those issues is to present them to the user as an underspecified constraint, and no geometric kernel is well designed to do that.

Re: Build123d: A Python CAD programming library

#63

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.

I'm no expert on self-reversing diamond thread but I think this generates what you're looking for. Are pictures allowed here?

    import copy
    from build123d import *
    from ocp_vscode import show_all

    od, p, n, d, e = 10 * MM, 12 * MM, 5, 1 * MM, 15 * MM

    with BuildPart() as thread_segment_builder:
        with BuildLine():
            path = Helix(p, 1.1 * p, od / 2 + 0.001)
        with BuildSketch(path ^ 0) as diamond:
            xsection = Polygon((0, d), (0, 0), (d, d / 2))
        track = sweep(is_frenet=True)
        # Trim the ends to align with Plane.XZ
        Box(2 * p, p, p / 2, align=(Align.MIN, Align.MAX, Align.MIN), mode=Mode.SUBTRACT)
        with Locations((0, 0, p)):
            Box(2 * p, p, p / 2, align=Align.MIN, mode=Mode.SUBTRACT)

    # Create the rod end with an extension beyond the threaded section
    with BuildPart() as threaded_rod_end_segment_builder:
        with Locations((0, 0, -e)):
            Cylinder(od / 2, p + e + d / 2, align=Align.NONE)
        add(thread_segment_builder.part, mode=Mode.SUBTRACT)
        add(mirror(thread_segment_builder.part, Plane.XZ), mode=Mode.SUBTRACT)


    # Position and trim the end and mid segments
    threaded_rod_end_segment = Pos(Z=-d / 2) * threaded_rod_end_segment_builder.part
    threaded_rod_mid_segment = split(threaded_rod_end_segment, Plane.XY)

    # Build the rod from copies which is very efficient
    threaded_rod = Compound(
        children=[Pos(Z=i * p) * copy.copy(threaded_rod_mid_segment) for i in range(n - 2)]
        + [
            Pos(Z=-p) * threaded_rod_end_segment,
            Pos(Z=p * (n - 1)) * (Rot(X=180) * copy.copy(threaded_rod_end_segment)),
        ]
    )

    show_all()

Re: Build123d: A Python CAD programming library

#64

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.

I'm no expert on self-reversing diamond thread but I think this generates what you're looking for. Are pictures allowed here? import copy from build123d import * from ocp_vscode import show_all od, p, n, d, e = 10 * MM, 12 * MM, 5, 1 * MM, 15 * MM with BuildPart() as thread_segment_builder: with BuildLine(): path = Helix(p, 1.1 * p, od / 2 + 0.001) with BuildSketch(path ^ 0) as diamond: xsection = Polygon((0, d), (0,…

A valiant attempt! Unfortunately, there are a bunch of artifacts after export_step() - I don't use vscode and show_all() was sidestepped - which break the thread, see https://postimg.cc/3kkzW94T Specifically, the end of thread is a hard diamond shape with a chunk missing, and the diamond threads don't cross over at all apparently because segments of the rod have rendered on top of others. python 3.13 build123d-0.10.0 cadquery_ocp_proxy-7.9.3.1

Re: Build123d: A Python CAD programming library

#65

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.

Ok here is my result, which matches up well with the examples I have found from McMaster Carr. Note that not all STEP importers are robust enough to deal with files from OCCT based CAD packages. As I mentioned previously there are transition arcs from the left to right hand helices on both ends which enable the automatic reversing behavior.

    from ocp_vscode import show_all
    from build123d import *

    od, p, n, d, e = 10 * MM, 12 * MM, 5, 1 * MM, 15 * MM
    base_helix = Helix(p, 2.2 * p, od / 2 + 0.001, center=(0, 0, -p))
    # retain a small piece below XY plane for orienting sketch
    trim_base_helix = base_helix.trim(0.4, 1)
    trim2_base_helix = trim_base_helix.trim(0, 0.72)

    p0 = trim2_base_helix @ 1
    t0 = (trim2_base_helix % 1).normalized()
    t1 = Vector(0, 1, 0).normalized()

    bisector = (t0 + t1).normalized()
    if bisector.length == 0:
        bisector = t0  # Fallback if tangents are perfectly opposite

    ray = Axis(p0, bisector)
    end_pt = ray.intersect(Plane.XZ)

    transition_arc = TangentArc(p0, end_pt, tangent=t0)

    rh_curve = Curve() + [trim2_base_helix, transition_arc]
    profile = (rh_curve ^ 0) * Rot(Z=99) * Circle(d)  # rotate seam out of the way
    rh_sweep = sweep(profile, rh_curve)
    splitter = Plane.XZ * Rectangle(10, 40, align=(Align.MIN, Align.CENTER)).face()
    rh_sweep = split(rh_sweep, bisect_by=splitter, keep=Keep.BOTH).solids()[1]
    lh_sweep = mirror(rh_sweep, about=Plane.XZ)

    both_sweeps = Part() + [rh_sweep, lh_sweep]

    cyl = Part() + Cylinder(od / 2, p + e + d / 2)
    cyl -= both_sweeps
    cyl = split(cyl, bisect_by=Plane.XY)
    cyl += mirror(cyl, about=Plane.XY)
    show_all()
I also tested the above in the online build123d-sandbox here, which worked great: https://jojain.github.io/build123d-sandbox

Re: Build123d: A Python CAD programming library

#66

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.

Ok here is my result, which matches up well with the examples I have found from McMaster Carr. Note that not all STEP importers are robust enough to deal with files from OCCT based CAD packages. As I mentioned previously there are transition arcs from the left to right hand helices on both ends which enable the automatic reversing behavior. from ocp_vscode import show_all from build123d import * od, p, n, d, e = 10 *…

This looks on the mark. Congratulations! You have succeeded where others failed.

Re: Build123d: A Python CAD programming library

#67
post #36
post #20

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).

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 :)

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.

Post reply on HN