gumyr / build123d

A python CAD programming library
Apache License 2.0
514 stars 88 forks source link

fillet silently fails to operate on a vertex in BuildSketch #314

Open jdegenstein opened 1 year ago

jdegenstein commented 1 year ago

This seems to occur more frequently on inside corners in my experience. I receive no warnings or error messages and the script runs "fine". Here is some code to reproduce the screenshot:

with BuildPart() as p:
    with BuildSketch(Plane.XZ.offset(5/2)) as s:
        with Locations((1.5,0)):
            SlotOverall(2.625*2,3,90)
            split(bisect_by=Plane.XZ,keep=Keep.BOTTOM)
        with Locations((1,0)):
            Rectangle(4-1,1.5,align=(Align.MIN,Align.MIN))
        with Locations((1.5,1.125)):
            Circle(.5/2,mode=Mode.SUBTRACT)
        vtxs = s.sketch.vertices().sort_by(Axis.X)[-3]
        fillet(vtxs,.1)
    extrude(amount=-.25)
    fillet(p.part.edges().filter_by(Axis.Y).sort_by(Axis.Z)[-1],.75)

show(p.part.translate((0,1,0)),s.sketch,vtxs)

image

gumyr commented 1 year ago

This problem is related to the sketch being created off of Plane.XY. With the following change (and removal of the final fillet):

        # vtxs = s.sketch.vertices().sort_by(Axis.X)[-3]
        vtxs = s.sketch_local.vertices().sort_by(Axis.X)[-3]

one gets: image In the original version, the vertex being selected is part of the relocated/global version of the sketch, not the one on Plane.XY/local that is actively being created. By changing the vertex selector to work on s.sketch_local the vertex is being selected on the actual sketch under construction and it works as expected. (Note is the screen shot the vertex to the right of the objects - this is the selected vertex on Plane.XY.)

So how can this be addressed? The fillet operation could (should?) be enhanced to check to see if the Vertex/Edge is actually part of the Shape being worked on. If not, as in this case, a ValueErrror should be generated. If the fillet operation is in the scope of BuildSketch, the error handling could even to see if the vertex is in one of the global sketches and not the local sketch and give a precise error message saying the user must select from sketch_local.

Any other ideas of how to address this?

jdegenstein commented 1 year ago

I do think better error handling is in order here to help new users.

In hindsight, I believe the "correct" approach is to use e.g. vtxs = s.vertices().sort_by(Axis.X)[-3] instead of vtxs = s.sketch.vertices().sort_by(Axis.X)[-3]. Example 16 in the intro docs uses the former approach. This is what I have done in the past, although I am not sure if there are any other benefits to using sketch_local.