I thought I might design and 3D-print something to repurpose components salvaged from a disassembled Harbor Freight mini LED flashlight. I still might do that, but another thought occurred to me: for the purpose of CadQuery practice, I don't need to invent something new, I can try to model the salvaged components themselves.

So I pulled out my calipers and started taking down dimensions for the front window, shiny reflector module, and the circuit board hosting the array of nine LEDs. The front window is trivial, a single flat cylinder, but it got more complex from there.

The good news is that, despite some worrisome early signs, CadQuery has proven to give me better feedback on my mistakes than FreeCAD has. Especially from code centric aspect of Python syntax errors because that gives me a line number of the problem. CQ-Editor also gives a very code centric capability to step through my CadQuery design line by line, which makes debugging much easier than trying to understand where I went wrong in a FreeCAD design.

The bad news is that I have yet to build a mental understanding of how CadQuery coordinate spaces work. I'm frequently confused by parts popping up at positions or orientations different than where I had expected. For some of these mistakes I could see my misunderstanding after the fact, for other mistakes I still don't understand where I went wrong.

    p = cq.Workplane("XZ")
    p = p.polygon(8,led_ring_diameter, forConstruction=True)
    p = p.vertices()
    p = p.eachpoint(
        lambda pos: (
            ring.add(
                make_led(),
                loc = pos,
                color = color_clear_plastic
                )
            )
        )

In this code snippet, I am working on the XZ plane and I drew a construction octagon on this plane. I then placed an LED at each vertex of that octagon, but they were position on the XY plane instead of the XZ plane.

Why did this happen? I have yet to figure out the root cause. So far I only have a workaround: insert extraneous intermediate CadQuery assemblies for the sake of rotating parts to where I had expected them. I know it isn't the right tool for the job, but I appreciate CadQuery giving me such tools to bludgeon my way to an imperfect but acceptable state. This is much preferred over FreeCAD's unhelpful "recompute failed!" leaving me staring at the screen with no recourse.